Topic "Check for folder existance"

Author Message


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.

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26858
Location: Prague, Czechia
You can set "option batch continue" before mkdir and reset it to "option batch on" afterwards.
Martin Prikryl

You can post new topics in this forum


What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License