Check that file exists: Difference between revisions

→‎{{header|AutoHotkey}}: Cleanup and example added
(→‎{{header|AutoHotkey}}: Cleanup and example added)
Line 46:
=={{header|AutoHotkey}}==
AutoHotkey’s FileExist() function returns an attribute string (a subset of "RASHNDOCT") if a matching file or directory is found. The attribute string must be parsed for the letter D to determine whether the match is a directory or file.
<br><br>
<lang autohotkey>ShowFileExist("input.txt")
Another option is AutoHotkey's IfExist/IfNotExist command
 
<lang autohotkey>; FileExist() function examples
<lang autohotkey>ShowFileExist("input.txt")
ShowFileExist("\input.txt")
ShowFolderExist("docs")
ShowFolderExist("\docs")
 
return
; IfExist/IfNotExist command examples (from documentation)
IfExist, D:\
MsgBox, The drive exists.
IfExist, D:\Docs\*.txt
MsgBox, At least one .txt file exists.
IfNotExist, C:\Temp\FlagFile.txt
MsgBox, The target file does not exist.
 
Return
 
ShowFileExist(file)
{
ifIf ( FileExist(file) && !InStr(FileExist(file), "D"))
MsgBox, file: %file% exists.
elseElse
MsgBox, file: %file% does NOT exist.
returnReturn
}
 
ShowFolderExist(folder)
{
ifIf InStr(FileExist(folder), "D")
MsgBox, folder: %folder% exists.
elseElse
MsgBox, folder: %folder% does NOT exist.
returnReturn
}</lang>