Skip to content
⌘ NSIS Forum Archive

IfFileExists on prefetch directory

3 posts

Yathosho#

IfFileExists on prefetch directory

i'm checking if the prefetch directory is empty
# method 1
IfFileExists "$WINDIR\Prefetch\*.*" NotEmpty

# method 2
FindFirst $0 $1 "$WINDIR\Prefetch\*.*"
both methods don't seem to work when the directoy is empty. method #2 always returns a dot ($1=.), unregarding whether the directory is empty or not. when i use either method to find a specific file, both methods work.

i tested the same code on different directories without any problems. any ideas?
mauvecloud#
In Windows, an "empty" directory isn't really empty. Except for the root directory, it always has at least the two special files "." and ".." (references to the current and parent directories, respectively). I think the safest way is to use StrCmp to check for "." and "..", and use FindNext to look for a file other than those.
Afrow UK#
StrCpy $2 0
ClearErrors
FindFirst $0 $1 "$WINDIR\Prefetch\*.*"
${Do}
${If} $1 != .
${AndIf} $1 != ..
StrCpy $2 1
${Break}
${EndIf}
FindNext $0 $1
${LoopUntil} ${Errors}
FindClose $0
Stu