Xfce Forum

Sub domains
 

You are not logged in.

#1 2014-08-05 19:47:36

birch
Member
Registered: 2014-07-12
Posts: 63

[Solved] Thunar Custom Action - Renaming Files

I have a command that I'm trying to get to work. It deletes spaces, hyphens, plusses and underscores from filenames.

qliSSE1.png
K1Ulmge.png

Code: rename "s/[-_+ ]//g" *

I've tried using this command by inserting the %f and n% command parameters in different places, but it doesn't work. When I run the command without the parameters then it will rename all files in a folder, and not just the selected files. How can I get it to rename only selected files.

Offline

#2 2014-08-05 22:54:15

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,494

Re: [Solved] Thunar Custom Action - Renaming Files

You need to create a loop so that all of the selected files in %N get processed individually. Something like this works:

for file in %N; do mv "$file" `echo $file | sed -e 's/[_-+ ]//g'`; done

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2014-08-05 23:07:55

birch
Member
Registered: 2014-07-12
Posts: 63

Re: [Solved] Thunar Custom Action - Renaming Files

Thank you! I just tested it and it works, but presents a new problem. It deletes the period that separates the file name from the file extension. So it will change 34faw-aajiew_areaf opoa.jpg to 34fawaajiewareafopoajpg

Offline

#4 2014-08-05 23:51:39

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,494

Re: [Solved] Thunar Custom Action - Renaming Files

Sorry, my QA failed me today. Try this one instead:

for file in %N; do mv "$file" `echo $file | sed -e 's/[ _+-]//g'`; done

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2014-08-06 00:36:29

birch
Member
Registered: 2014-07-12
Posts: 63

Re: [Solved] Thunar Custom Action - Renaming Files

Thanks, that works perfect!

Offline

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

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.007 seconds, 10 queries executed - Memory usage: 529.18 KiB (Peak: 530.46 KiB) ]