Topic "C# Directory Masking"

Author Message
[View user's profile]

Joined: 2016-11-02
Posts: 1
Hi all,

I am currently putting together a small tool to move files into a folder and then transfer them to my local machine. I have the transfer etc all working perfectly, but I am struggling with the move section.

Scenario: Source location has many folders and loose files... I intend to collect the loose files, put them into a new folder and then transfer the new folder. BUT - I only want to move the "Loose" files into a new folder and ignore any other folders in the source location.

e.g. I have a source with:

Folder 1
Folder 2
Folder 3
loose file 1
loose file 2
loose file 3
loose file 4

I want to create a "Folder 4" and then move the 4 loose files into the folder, then transfer.

so it becomes:
Folder 1
Folder 2
Folder 3
Folder 4

I then transfer the content of Folder 4 to my local machine. As i said, my transfer works fine - no issues here, the creation of folder 4 works fine, no issues there either. My issue is the moving of loose files into the "Folder 4" - it keeps trying to move the folders too. I have tried putting "*" at the start of the source folder, but it crashes.

as a note - every time I run this, there will be different folders, so i cant hard code what to ignore.

my code so far for the move:


      string localPath = txtBoxLocalDest.Text;
      string remotePath = txtBoxRemoteLoc.Text;
      string movePath = remotePath + "/*";
      string remoteFilePath = remotePath + "/" + txtBoxNewFolderName.Text;

      // Create remote subdirectory, if it does not exist yet
      if (!session.FileExists(remoteFilePath))
      //move loose files into new subdirectory
      session.MoveFile(movePath, remoteFilePath);

thank you for any support provided.
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27083
Location: Prague, Czechia
Use the Session.EnumerateRemoteFiles method to retrieve list of the files and call the Session.MoveFile for each.

Note that the Session.MoveFile officially does not support masks. So your current code may break in future versions of WinSCP anyway.

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