Page 1 of 1

If statement: Check if folder does NOT exist.

Posted: Tue Nov 19, 2013 3:51 pm
by acascianelli
Looking to write a small if statement to see if a folder exists, and if it does not go ahead a create it. One caveat is that the foldername contains a variable. Here's what I got so far but it isn't working. Would appreciate a little assistance...
Code: Select all
<timestamp version="1.0">
     <format outputVariable="currentDate" pattern="yyyyMMdd" />
</timestamp>

<if label="if: folder exists" condition="${FileInfo(&apos;/opt/Linoma_Software/GoAnywhere_Services/share/webdocs/MDT/Datamail/Archived/${currentDate}&apos;):exists == false}" logLevel="debug">
     <mkdir dir="/opt/Linoma_Software/GoAnywhere_Services/share/webdocs/MDT/Datamail/Archived/${currentDate}" version="1.0" />
</if>

Re: If statement: Check if folder does NOT exist.

Posted: Tue Nov 19, 2013 4:10 pm
by Support_Rick
Tony,

Just remove the IF statement and just do the MKDIR. Just change it to ignore the error if the folder already exists. That way you'll see the MKDIR in the job log, but it will tell you if the folder was created or not. And, more importantly, continue processing either way, by making sure the folder already exists or creating when needed.
Code: Select all
<mkdir dir=".../Archived/${currentDate}" onError="continue" version="1.0" />

Re: If statement: Check if folder does NOT exist.

Posted: Tue Nov 19, 2013 4:15 pm
by acascianelli
Thanks Rick.

I was trying to be fancier than I needed to be I guess. Seems to be a common problem I'm running into today...

Re: If statement: Check if folder does NOT exist.

Posted: Wed Nov 20, 2013 11:15 am
by acascianelli
Is there any way to have the error message in the job log suppressed in the event that the folder is already present?

Re: If statement: Check if folder does NOT exist.

Posted: Wed Nov 20, 2013 11:30 am
by Support_Rick
You can suppress the message by changing the loglevel ... like so.
Code: Select all
<mkdir label="Create Dirs" dir="...\MyDir\MySubDir" version="1.0" logLevel="silent" onError="continue" />
But, this would remove it altogether. Normal and Verbose might give you different values. Might want to check them out as well.