Simple Question About IfFileExists

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ADP_MAN
Junior Coder
Posts: 45
Joined: Wed Apr 07, 2004 2:04 pm

Simple Question About IfFileExists

Post by ADP_MAN » Thu Oct 27, 2016 2:57 pm

Hi All,

Simple question I'm hoping someone can help me with. I'm monitoring a folder and if a file appears, I would like that to trigger something (for my example just a MessageModal). I'm using the following:

Label>Start
IfFileExists>C:\00 - TEST 2\*.*
Wait>3
//SEND TRUE MESSAGE
MessageModal>Hello! It Worked!
Wait>1
Endif
Wait>1
//SEND FALSE MESSAGE
MessageModal>This folder is empty.
Goto>Start
Label>End


The problem is even when there isn't a file in this folder I still get the first message "Hello! It Worked". Is this because of my usage of the wildcard ("*.*")? I was assuming the wildcard would bet "true" when there was a file present, and "false" when not.

Thanks in advance,
ADP

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Simple Question About IfFileExists

Post by JRL » Thu Oct 27, 2016 4:41 pm

The problem is even when there isn't a file in this folder I still get the first message "Hello! It Worked".
That is because you are searching for "*.*". IfFileExists> also detects folders. Even a file free folder contains two special folders named "." and "..". You will see them if you open a DOS prompt and type "Dir" then press enter.

Is there any commonality in the incoming file names? Even a single character that will be common in all file names? For example if all files contain a "T" you could do IfFileExists>C:\00 - TEST 2\*t*.*

Otherwise I would suggest using DOS and writing results to a file then looping to see when the result file has contents.

Something Like:

Code: Select all

Let>RP_Wait=1
Let RP_WindowMode=0
RunProgram>cmd /c Dir "C:\00 - TEST 2\*.*" /a-d /b > %temp_dir%FileExistsResult.txt
FileSize>%temp_dir%FileExistsResult.txt,vFSize
If>vFSize>0
Would replace the line

Code: Select all

IfFileExists>C:\00 - TEST 2\*.*

ADP_MAN
Junior Coder
Posts: 45
Joined: Wed Apr 07, 2004 2:04 pm

Re: Simple Question About IfFileExists

Post by ADP_MAN » Thu Oct 27, 2016 6:49 pm

Hi JRL,

I did manage to find some commonality and it worked. Thanks for the suggestion.

ADP

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Simple Question About IfFileExists

Post by CyberCitizen » Fri Oct 28, 2016 2:16 am

Also watch out for hidden system files etc something like desktop.ini

I don't know if MS detects these in the folders as well with those commands.
FIREFIGHTER

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts