If statement: Check if folder does NOT exist.

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
5 posts Page 1 of 1

acascianelli

Posts: 4
Joined: Fri May 17, 2013 1:17 pm

Post by acascianelli » Tue Nov 19, 2013 3:51 pm
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>

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Tue Nov 19, 2013 4:10 pm
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" />
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696

acascianelli

Posts: 4
Joined: Fri May 17, 2013 1:17 pm

Post by acascianelli » Tue Nov 19, 2013 4:15 pm
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...

acascianelli

Posts: 4
Joined: Fri May 17, 2013 1:17 pm

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

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Wed Nov 20, 2013 11:30 am
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.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
5 posts Page 1 of 1