Post a reply

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: Directory assistance

I am using this in an SSIS package and have been able to build a C# script to delete empty directories with the following:
public void Main()
        Dts.TaskResult = (int)ScriptResults.Success;
    catch (Exception ex)
        Dts.TaskResult = (int)ScriptResults.Failure;
private static void ProcessDirectory(string startLocation)
    foreach (var directory in Directory.GetDirectories(startLocation))
        if (Directory.GetFiles(directory).Length == 0 && Directory.GetDirectories(directory).Length == 0)
            Directory.Delete(directory, false);

Re: Directory assistance

Awesome! Thank you Martin! I have played around with the .NET assembly and have been able to everything I can with the scripting, and more with file and directory control.

Re: Directory assistance

Option not to transfer "empty" directories in on TODO list:
Issue 207 – Do not synchronize/transfer empty directories

Meanwhile, your only option is to script the transfer using .NET assembly (e.g. in PowerShell).

Your task is somewhat similar to this:
Recursively move files in directory tree to/from SFTP/FTP server while preserving source directory structure
So you can base your script on that.

To preserve timestamps of directories, you can use PreserveTimeDirs settings:
(edited in 2022)

Though that affects newly created folders. If you want to update timestamps of modified folders, WinSCP cannot do that. Again, you would have to script it (e.g. in PowerShell as above).

Directory assistance

Looking for some help determining where I am making a mistake. I have a script that will remove files older than 14 days then get files from the previous day (24 hrs). The issue I am having is that its also bringing over every directory empty as well.
For instance I have directory 01234 with 3 files (1.wav, 2.wav and 3.wav) in it. The creation date (or modified date) is from 3 days back, so I really want to ignore it. I also have directory 56789 with 1 file in it (4.wav) and a creation date (modified date) within the last 24 hours.
Currently the directories 01234 and 56789 are being brought over (with a current timestamp btw) then are being loaded only if it is within the last day. In this case 56789 gets the 4.wav (with the timestamp preserved on the .wav file).

How can I get it to 1) ignore directory 01234 and 2) preserve the timestamp on directory 56789 not just the files in 56789? Any thoughts?

(Side note: I have a batch file passing in the directory at %1% with the /parameter command)
Batch file:
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set year=%dt:~0,4%
set month=%dt:~4,2%
if %month%==01 set month=Jan
if %month%==02 set month=Feb
if %month%==03 set month=Mar
if %month%==04 set month=Apr
if %month%==05 set month=May
if %month%==06 set month=Jun
if %month%==07 set month=Jul
if %month%==08 set month=Aug
if %month%==09 set month=Sep
if %month%==10 set month=Oct
if %month%==11 set month=Nov
if %month%==12 set month=Dec
set filePath=\\fileserver\Dir1\%year%\%month%\
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /script=FTPScript.txt /parameter %filePath% /log=FTPlog.txt

option confirm off
option batch on
open s -hostkey="Some Host Key"
rm *<14D
get -preservetime -filemask="*>=1D" / %1%