Xfce Forum

Sub domains
 

You are not logged in.

#1 2022-10-12 01:50:12

fixit
Member
Registered: 2015-01-19
Posts: 115

Compress files containing only spaces and no file extension

I have been using this custom action.

But for a project I needed to rename some .png files to filenames using only spaces and no extension.

zip -u -j %n.zip %F

But now it does not zip those files?

Any fix?


Ubuntu-Mate 22.04

Offline

#2 2022-10-12 06:36:31

PaperNick
Member
Registered: 2013-05-26
Posts: 106

Re: Compress files containing only spaces and no file extension

Hey, the problem is that files containing only spaces break the zip command as currently defined.

A possible solution would be to check whether the %n param is empty and provide a default archive name.

zipname="$(echo %n | xargs)"; zip -u -j "${zipname:-Archive}".zip %F

Breaking down how it works:
1. We assign the %n value to a variable and trim any leading whitespace using xargs
2. Through bash parameter expansion we provide a default value in case zipname is empty - Archive

Offline

#3 2022-10-12 21:26:48

fixit
Member
Registered: 2015-01-19
Posts: 115

Re: Compress files containing only spaces and no file extension

Thanks PaperNick.


Ubuntu-Mate 22.04

Offline

Board footer

Powered by FluxBB