2

I am using WinSCP and it has the option to use custom commands remotely.

I want to zip some files and folders. WinSCP has a command that can zip a file or folder but I have to enter the name for the zip to be called.

zip -r "!?&Enter an Archive Name:?archive.zip!" !&

I would like a command that will take the name of the file and use that for the zip.

I.e. thisnewvideo.mp4 to become thisnewvideo.zip.

I have a lot of files so typing each title will take a long time.

If it is possible I would like to be able to do multiple files at once and create a separate zip file for each file or folder keeping to original file or folder title.

It needs to be a zip file.

Jawa
  • 3,649
Ezdub
  • 21

2 Answers2

0

WinSCP does not have a pattern or any other mechanism to extract filename without extension (or substitute the extension).

Anyway, you can use any function that the server provides to achieve the same. For example you can replace the extension using the sed command:

echo thisnewvideo.mp4 | sed 's/\..*$/.zip/'

This will output:

 thisnewvideo.zip

You can merge this into the WinSCP custom command using backtick operator like:

zip -r `echo ! | sed 's/\..*$/.zip/'` !

Note that the command is using the ! pattern. When you execute it for a set of selected files, it gets executed once for every file, producing one .zip file for every source file.

For alternatives see: Extract filename and extension in Bash.

Note that I would consider better (and easier) to implement it to just append the .zip extension (i.e. thisnewvideo.mp4.zip) to the end of the file name, rather than substituting the extension. You would avoid name clashes, if you have two files with the same base name, just a different extension. But I do not know your constraints.

0
zip -r `echo ! | sed 's/\..*$/.zip/'` !

It's ok if you want multiple zip

And monster like that

ls -q !& > list_1239.txt; zip -9 "!?&FileName:?archive.zip!" $(cat list_1239.txt); rm list_1239.txt

if you want one big zip-file with custom name

byKos
  • 1