C# Directory Masking

Advertisement

Aldor
Joined:
Posts:
1

C# Directory Masking

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:

session.Open(sessionOptions);

      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))
      {
          session.CreateDirectory(remoteFilePath);
      }
      //move loose files into new subdirectory
      session.MoveFile(movePath, remoteFilePath);

thank you for any support provided.

Reply with quote

Advertisement

Advertisement

You cannot post new topics in this forum