Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Re: Check for folder existance

You can set "option batch continue" before mkdir and reset it to "option batch on" afterwards.

Check for folder existance

I'm writing a winscp script. How do I check to see if a folder exists? I need to create the folder if it doesn't exist. In most cases, the folder will already exists, but when it doesn't, I need to create it.

So I'm using the mkdir command. But this reports an error if it attempts to create the folder and it already exists. I returning the resulting status to a batch file so I can report success or failure, so I don't want the error.

Here is the script:

# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
# Force binary mode transfer
option transfer binary
option synchdelete on
# Change remote directory
cd /home/user/web
# Upload the file to current remote directory
put data.tss
# Make remote directory if it doesn't exist
mkdir /home/user/web/data-Web
# Change remote directory
cd /home/user/web/data-Web
# Change local directory
lcd data-Web
# Synchronize remote with local
synchronize remote
# Disconnect
# Exit WinSCP

I sure wish I could "pause" at the end too so that I can review the session before the window closes.