This code works as it should:
IfFileExists "${DISTFILES_PATH}\$R0" 0 +3
MessageBox MB_OK "GetSize"
MessageBox MB_OK "Returned size $0"
MessageBox MB_OK "Next Function"
This code works strangely:
IfFileExists "${DISTFILES_PATH}\$R0" 0 +3
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Got size $0"
MessageBox MB_OK "Next Function"
Note: the file DOES NOT EXIST.
the second code returns "Got size " (no size, however) so I'm guessing it tried to get the size eventhough the file didn't exist.
if I change +3 in IfFileExists to +4, I get "Got size success", and if I change it to +5, I get "Got size 18320" or something like that.
can anyone explain any of this?
getfilesize bug?
9 posts
Instead of ${GetSize} I'd suggest this one Get File Size using the system plugin from wiki. Give it a try, could solve your problem.
${GetSize} it is macro you shouldn't use relative jumps
IfFileExists "${DISTFILES_PATH}\$R0" 0 notexist
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Got size $0"
notexist:
MessageBox MB_OK "Next Function"This is 'not exists' handling in the GetSize macro
So you can check $0 is empty or add IfErrors after the macro (see 4.9.4.18 SetErrors).error:
SetErrors
StrCpy $0 ''
StrCpy $1 ''
StrCpy $2 ''
as Instructor mentionent above, it works fine with labels.
this one works fine:
this one works fine:
as well as this one:!define DISTFILES_PATH 'D:\new'
name 'DISTFILES'
outfile 'distfiles.exe'
!include 'FileFunc.nsh'
!insertmacro GetSize
Function .onInit
push 'exists.dll' ; example file exists
pop $R0
IfFileExists "${DISTFILES_PATH}\$R0" _getsize _nextfunc
_getsize:
;MessageBox MB_OK "GetSize"
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Returned size $0"
_nextfunc:
MessageBox MB_OK "Next Function"
functionend
section -
sectionend
!define DISTFILES_PATH 'D:\new'
name 'DISTFILES'
outfile 'distfiles.exe'
!include 'FileFunc.nsh'
!insertmacro GetSize
Function .onInit
push 'not_exists.dll' ; example file does not exist
pop $R0
IfFileExists "${DISTFILES_PATH}\$R0" _getsize _nextfunc
_getsize:
;MessageBox MB_OK "GetSize"
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Returned size $0"
_nextfunc:
MessageBox MB_OK "Next Function"
functionend
section -
sectionend
Originally posted by Takhirthanks alot that worked wonders 🙂
This is 'not exists' handling in the GetSize macroSo you can check $0 is empty or add IfErrors after the macro (see 4.9.4.18 SetErrors).error:
SetErrors
StrCpy $0 ''
StrCpy $1 ''
StrCpy $2 ''
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $7 $8 $9
StrCmp $7 "" +2 0
StrCpy $0 $7You should use the LogicLib. It'd save you a lot of trouble like this one.
!include LogicLib.nsh
# ...
${If} ${FileExists} ${DISTFILES_PATH}\$R0
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Got size $0"
MessageBox MB_OK "Next Function"
${EndIf}
wow i had no idea you could use logiclib with fileexists, thanks alot for that
You can use it with anything, even if there's no wrapper macro for it. For example:
${If} ${Cmd} `IfFileExists "$WINDIR\notepad.exe"`
DetailPrint "exists"
${Else}
DetailPrint "doesn't exist"
${EndIf}