Xfce Forum

Sub domains
 

You are not logged in.

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

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

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 24.04

Offline

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

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

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: 129

Re: Compress files containing only spaces and no file extension

Thanks PaperNick.


Ubuntu-Mate 24.04

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.008 seconds, 7 queries executed - Memory usage: 533.28 KiB (Peak: 544.62 KiB) ]