FileExist() "blind spots" Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

FileExist() "blind spots"

Post by JBensimon » 22 Mar 2023, 21:16

This may have been reported previously, but some files that manifestly exist (for example C:\pagefile.sys and C:\swapfile.sys) are not detected as existing by FileExist() (which returns an empty string) or even by the old IfExist command, yet are fully recognized by Attrib.exe (which correctly displays their attributes) or by CMD's "If Exist ..." syntax.

Is there a workaround within AutoHotkey (i.e. not involving an external program)? [planning to look into possibly using WMI, but I thought I'd ask as well -- also wondering whether AHK v2 has better luck detecting such files].

Thanks.

JB

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: FileExist() "blind spots"  Topic is solved

Post by mikeyww » 22 Mar 2023, 21:45

Code: Select all

#Requires AutoHotkey v1.1.33
Loop Files, C:\swapfile.sys
 found := True
If found
     MsgBox 64, Status, Found it!
Else MsgBox 48, Status, Nope!

JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

Re: FileExist() "blind spots"

Post by JBensimon » 22 Mar 2023, 22:14

Excellent, Mikey! That'll work very nicely.

I'd considered that but using the parent folder with a wildcard (like Loop, Files, C:\* in this case) but that seemed highly inefficient to check for a single file's existence-- totally forgot that a single file can be specified (event though I frequently use that method to convert relative filespecs to fully qualified via A_LoopFileLongPath).

Thanks again.

Post Reply

Return to “Ask for Help (v1)”