DirState: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|Instructor}}
|<small>Author: [[{{ns:2}}:Instructor|Instructor]] ([[{{ns:3}}:Instructor|talk]], [[{{ns:-1}}:Contributions/Instructor|contrib]])</small>
|}
<br style="clear:both;">
== Links ==
; Latest version of headers "nsh.zip":
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost


If function used without header then put function in script before call it
{{User:Instructor/Headers/Template}}


== The Function ==
== Function Description ==
<highlight-nsis>/*
 
<highlight-nsis>
____________________________________________________________________________
____________________________________________________________________________


Line 16: Line 11:
____________________________________________________________________________
____________________________________________________________________________


2004 Shengalts Aleksander (Shengalts@mail.ru)


Check directory full, empty or not exist.


Check directory full or empty.


Syntax:
${DirState} "[path]" $var


Syntax:
"[path]"      ; Directory
Push "[path]"      ; [path]
$var          ; Result:
                  ;  Directory
              ;   $var=0  (empty)
Call DirState      ; Call function
              ;   $var=1  (full)
                  ;
              ;   $var=-1 (directory not found)
Pop $var          ; $var=0  (empty)
</highlight-nsis>
                  ; $var=1  (full)
                  ; $var=-1 (directory not found)




Example:
<b>Example:</b>
Section
<highlight-nsis>Section
Push "$TEMP"
${DirState} "$TEMP" $R0
Call DirState
; $R0="1"  directory is full
Pop $R0  ; $R0="1"  directory is full
SectionEnd
SectionEnd*/
</highlight-nsis>


== Function Code ==


;---------------------------------------------------------------------------
<highlight-nsis>
Function DirState
Function DirState
!define DirState `!insertmacro DirStateCall`
!macro DirStateCall _PATH _RESULT
Push `${_PATH}`
Call DirState
Pop ${_RESULT}
!macroend
Exch $0
Exch $0
Push $1
Push $1
ClearErrors


FindFirst $1 $0 '$0\*.*'
FindFirst $1 $0 '$0\*.*'
Line 64: Line 68:
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
[[Category:Disk, Path & File Functions]]

Latest revision as of 10:38, 26 April 2011

Author: Instructor (talk, contrib)


Page for NSIS 2.07 and below users

You can use the latest version of headers (recommended) or the following function code (put the function code in your script before calling it)

Function Description

____________________________________________________________________________
 
                            DirState
____________________________________________________________________________
 
 
Check directory full, empty or not exist.
 
 
Syntax:
${DirState} "[path]" $var
 
"[path]"      ; Directory
$var          ; Result:
              ;    $var=0  (empty)
              ;    $var=1  (full)
              ;    $var=-1 (directory not found)


Example:

Section
	${DirState} "$TEMP" $R0
	; $R0="1"  directory is full
SectionEnd

Function Code

Function DirState
	!define DirState `!insertmacro DirStateCall`
 
	!macro DirStateCall _PATH _RESULT
		Push `${_PATH}`
		Call DirState
		Pop ${_RESULT}
	!macroend
 
	Exch $0
	Push $1
	ClearErrors
 
	FindFirst $1 $0 '$0\*.*'
	IfErrors 0 +3
	StrCpy $0 -1
	goto end
	StrCmp $0 '.' 0 +4
	FindNext $1 $0
	StrCmp $0 '..' 0 +2
	FindNext $1 $0
	FindClose $1
	IfErrors 0 +3
	StrCpy $0 0
	goto end
	StrCpy $0 1
 
	end:
	Pop $1
	Exch $0
FunctionEnd