Ignore folder structure when copying the files.

Advertisement

macservice123
Joined:
Posts:
1
Location:
hanoi

Ignore folder structure when copying the files.

Hello,

Is it possible to ignore local directory file structure when copying files?
Let's say we've got a couple of files in subdirectories as follows:
./testa00.txt 
./testb00.txt 
./01/testa01.txt 
./01/testb01.txt 
./02/testa02.txt 
./02/testb02.txt

Is there a way to put those 'testa*.txt' files on FTP server without copying the folder structure. Ideally, I would like all the files to be dropped into a single folder on the FTP server, is there a way to do it?

Thanks
Cristiano

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,567
Location:
Prague, Czechia

Re: Ignore folder structure when copying the files.

You can write a simple PowerShell script for that.
We have an example for download:
https://winscp.net/eng/docs/script_download_files_to_same_folder

Upload would be similar.

Actually, this code will do what you want:
https://winscp.net/eng/docs/library_example_moves_files_keeping_directory_structure#upload_powershell
If you modify it to:
1) replace $remoteFilePath with $remotePath in the $session.PutFiles call
2) remove if (!($session.FileExists($remoteFilePath))) { $session.CreateDirectory($remoteFilePath) }

It's just unnecessarily complicated for your simpler needs.
On the other hand, it's prepared to be used as a WinSCP extension, so it can be installed into WinSCP GUI.
https://winscp.net/eng/docs/extension

For a simple code, see
https://stackoverflow.com/q/43716807/850848

Reply with quote

Rockwell
Guest

Re: Ignore folder structure when copying the files.

Hey Martin! I could load the extension into the WinSCP but can't figure how to run this to the actual synchronization.

Reply with quote

Advertisement

You can post new topics in this forum