Topic "Move all files (only files not subdirs) in current directory"

Author Message
andresp
[View user's profile]

Joined: 2014-11-08
Posts: 4
I was hoping

Code:
mv *.* newDirectory/


would do it, but that also moves the directories in the current directory.

Is there any way to move only the files?

Thanks
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25025
Location: Prague, Czechia
It's not possible with scripting. But you can easily do this from PowerShell via WinSCP .NET assembly.
_________________
Martin Prikryl
frustrated

Guest


Part of the issue is that sub-directories that don't match the filemask are moved

mv *.* /some/other/dir/

shouldn't move anything that doesn't have a period on the name.
sub-directories without a period in the name are moved.

This is also true for the get command.

frustrating
MarkZZ

Guest


prikryl wrote:
It's not possible with scripting. But you can easily do this from PowerShell via WinSCP .NET assembly.


What would be the correct way to use the powershell transferOptions? I have a script that I need to upload only the text files from a directory tree and dump them all into one folder on the destination server rather than mirror the directory tree. The following setup seems to send only text files but also mirrors the directory tree:

# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.filemask = "*.txt"

$transferResult = $session.PutFiles("c:\test2\", "/Home/*", $False, $transferOptions)

Any advice?
MarkZZZ

Guest


MarkZZ wrote:
prikryl wrote:
It's not possible with scripting. But you can easily do this from PowerShell via WinSCP .NET assembly.


What would be the correct way to use the powershell transferOptions? I have a script that I need to upload only the text files from a directory tree and dump them all into one folder on the destination server rather than mirror the directory tree. The following setup seems to send only text files but also mirrors the directory tree:

# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.filemask = "*.txt"

$transferResult = $session.PutFiles("c:\test2\", "/Home/*", $False, $transferOptions)

Any advice?


Ok so I figured out a solution to this problem - I had to create batch file that iterates through each of the subfolders and then calls a winscp.exe script to send only the files.

The contents of the batch file is as follows:
Code:
cd C:\test2
for /D /r %%i in (*) do (
cd %%i
"C:\Program Files\winscp556\winscp.exe" /console /script="C:\Program Files\winscp556\UploadScript.txt"
)


and the contents of the upload script are basically:

Code:
option batch on
option confirm off
open user:password@sftp.somesite.com  -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx"
option transfer binary
put -filemask="|*/" *.txt>24H
close
exit


If there is a better way (powershell preferred) I'd love to see the example code!

Thanks,

Mark
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25025
Location: Prague, Czechia
Your original question what about mv. So it seems that you have completely changed topic.

Your solution with iterating folders in a batch file is correct.
You can do the same in PowerShell. I do not have an example handy. Will consider creating one.

Regarding the *.* mask, see https://winscp.net/eng/docs/file_mask#exceptions
Advertisements

You can post new topics in this forum






Search Site

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!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License