Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

IfExist ...


  • Please log in to reply
1 reply to this topic
Beastmaster
  • Guests
  • Last active:
  • Joined: --
I want to solve this issue:

a) check if there are any files! in a specified folder
B) If YES - filter for files with specified file extensions
c) If NO - wait and check again later

but ...

If you're checking only for files (*.*) it will work, as long there's no subdir (which of course seems to follow the current spec of IfExist). An Exclude parameter would be helpfull to prevent a dir from being identified as a file (look-a-like).


IfExist seems not to work with multiple wildcarding ...\*.txt;*.doc;*.rtf :?:

Currently I'm forced to use DOS to pipe the result into a file and check that afterwards :cry:

Run, %COMSPEC% /C dir \*.txt;*.doc;*.rtf > \DirStatus.txt

(Yes, instead I could use the same AHK command for each file extension separately, which I would hate cause than I'm back to do obviously repetitive tasks :cry: )

Any advice ? Further improvement on IfExist would be highly appreciated :D Thanx :wink:

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
To check if a folder contains at least one file, regardless of how many subfolders it has:
file_count = 0
Loop, C:\My Folder\*.*
     file_count++

To check if a folder contains at least one file of a specified type:
doc_file_count = 0
Loop, C:\My Folder\*.txt
     doc_file_count++
Loop, C:\My Folder\*.rtf
     doc_file_count++
Loop, C:\My Folder\*.doc
     doc_file_count++
if doc_file_count > 0
     MsgBox, The folder contains %doc_file_count% document files.

Thanks for your suggestion about enhancing IfExist. It might be a while before it gets done since the above is a good workaround.