Xfce Forum

Sub domains
 

You are not logged in.

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

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

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
Moderator
From: Canada
Registered: 2011-06-02
Posts: 5,969

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.

Offline

#3 2019-11-07 04:59:53

Skaperen
Member
From: surface of planet Earth
Registered: 2013-06-15
Posts: 455

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

Board footer

Powered by FluxBB