Xfce Forum

Sub domains
 

You are not logged in.

#1 2019-11-06 18:50:40

ArON
Member
Registered: 2018-11-06
Posts: 13

Custom Actions: How to replace spaces with underscores in file names?

Say we have a file named "abc 123.pdf", what could we put into Command in Custom Actions to rename it to "abc_122.pdf"?

Thank you very much!

Offline

#2 2019-11-06 21:40:42

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

Re: Custom Actions: How to replace spaces with underscores in file names?

Here is one way:

First, create a script file with the following content:

#!/bin/bash

for f in "$@"
do
        mv "$f" $(echo "$f" | sed -e 's/ /_/g')
done

...and make the file executable and save it somewhere in your PATH. For the sake of this example, lets call it /usr/local/bin/sp.

Then create a Thunar custom action with the following command:

sp %F

...and make sure to select all options on the Appearance Conditions tab.


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 2019-11-07 04:59:53

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 862

Re: Custom Actions: How to replace spaces with underscores in file names?

if you have the "rename" command (written in perl), it can apply a pcre to the names of globs of files.  for example:

rename -v 's/ /_/' *

Offline

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

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.012 seconds, 7 queries executed - Memory usage: 523.26 KiB (Peak: 530.63 KiB) ]