Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Renaming files in directory A with filenames in directory B

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
dauddaud1
Posts: 4
Joined: 2012-10-21 21:38

Renaming files in directory A with filenames in directory B

#1 Post by dauddaud1 »

I have two versions of an album in two directories. The first contains files in .mp3 format.
The second contains the same tracks in .flac format.

The mp3 files are older and I have already renamed them to fit my preferred system.

I now want to switch to using .flac files but do not want to retype (or copy one by one) the filename from one directory to the other.

For example:
daud@debian:~/Music/Blues/ElmoreJames/Disc2$ ls -lh
-rw-r--r-- 1 daud daud 6.5M Sep 14 2020 01_2_TheSunIsShining.mp3
-rw-r--r-- 1 daud daud 5.4M Sep 14 2020 02_2_ICantHoldOut.mp3
-rw-r--r-- 1 daud daud 5.8M Sep 14 2020 03_2_StormyMondayBlues.mp3
...
drwxr-xr-x 2 daud daud 4.0K Jul 21 15:29 flac

daud@debian:~/Music/Blues/ElmoreJames/Disc2/flac$ ls -lh
-rw-r--r-- 1 daud daud 12M Jul 21 14:17 01 - The Sun Is Shining.flac
-rw-r--r-- 1 daud daud 9.7M Jul 21 14:18 02 - I Can't Hold Out.flac
-rw-r--r-- 1 daud daud 11M Jul 21 14:17 03 - Stormy Monday Blues.flac
...

The desired outcome would be:

daud@debian:~/Music/Blues/ElmoreJames/KingOfTheSlideGuitar/Disc2/flac$ ls -lh
-rw-r--r-- 1 daud daud 12M Jul 21 14:17 01_2_TheSunIsShining.flac
-rw-r--r-- 1 daud daud 9.7M Jul 21 14:18 02_2_ICantHoldOut.flac
-rw-r--r-- 1 daud daud 11M Jul 21 14:17 03_2_StormyMondayBlues.flac

a. Can anyone kindly show me how to achieve this (explicitly)?
b. Can anyone point me to an elementary source where I can learn to do this and other "filename manipulation" tasks.

Thanks
D2

User avatar
esp7
Posts: 177
Joined: 2013-06-23 20:31
Has thanked: 2 times
Been thanked: 4 times

Re: Renaming files in directory A with filenames in directory B

#2 Post by esp7 »

XFCE's Bulk Renamer can easily achieve this. There are probably more tools, but as XFCE user, this is the one quickly coming to my mind: https://docs.xfce.org/xfce/thunar/4.10/ ... amer/start
ThinkPad X220: i5-2520M CPU 2.5GHz - 8GB RAM 1333 MHz - SSD 860 EVO 250GB - Debian - ME_cleaned
ThinkPad X230: i5-3320M CPU 3.3GHz - 8GB RAM 1600 MHz - SSD 860 EVO 500GB - Debian - ME_cleaned

dauddaud1
Posts: 4
Joined: 2012-10-21 21:38

Re: Renaming files in directory A with filenames in directory B

#3 Post by dauddaud1 »

esp7 wrote: 2021-07-21 17:47 XFCE's Bulk Renamer can easily achieve this. There are probably more tools, but as XFCE user, this is the one quickly coming to my mind: https://docs.xfce.org/xfce/thunar/4.10/ ... amer/start
Thx for your response.
I am familiar with Thunar's Bulk Renamer and use it regularly.

However, I have not been able to find a way to have it read the filenames (but not extensions) in one directory and apply them to files in another directory.

What I suppose I need is a script using sed and/or awk and regexes/other variables to parse a filename and feed it to mv/rename/a.n.other.
I do not currently have the skills to write this.
Furthermore, I have been unable to formulate a query for DDG or Google that produces answers other than how to (bulk) rename files.

User avatar
sunrat
Administrator
Administrator
Posts: 6457
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 472 times

Re: Renaming files in directory A with filenames in directory B

#4 Post by sunrat »

Are your flac files properly tagged? I use EasyTAG to rename files using their tags.
It can also rename files from a text file of filenames. You could create a text file from the mp3s with

Code: Select all

ls > filenames.txt
or if there are other files in the directory, filter mp3s with grep:

Code: Select all

ls |grep mp3 > filenames.txt
Name of the text file doesn't matter. In EasyTAG from the menu bar, Miscellaneous > Load Filenames From a Text File... . Then use a for loop to change "mp3" to "flac":

Code: Select all

for i in *.mp3; do mv -- "$i" "${i%.mp3}.flac"; done
Or use a rename utility to change "mp3" to "flac". I don't use Xfce but the Bulk Renamer in Double Commander file manager functions similarly. Double Commander is quite light and useful for other tasks as well.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

dauddaud1
Posts: 4
Joined: 2012-10-21 21:38

SOLVED Re: Renaming files in directory A with filenames in directory B

#5 Post by dauddaud1 »

sunrat wrote: 2021-07-21 23:55 Are your flac files properly tagged? I use EasyTAG to rename files using their tags.
It can also rename files from a text file of filenames. You could create a text file from the mp3s with

Code: Select all

ls > filenames.txt
or if there are other files in the directory, filter mp3s with grep:

Code: Select all

ls |grep mp3 > filenames.txt
Name of the text file doesn't matter. In EasyTAG from the menu bar, Miscellaneous > Load Filenames From a Text File... . Then use a for loop to change "mp3" to "flac":

Code: Select all

for i in *.mp3; do mv -- "$i" "${i%.mp3}.flac"; done
Or use a rename utility to change "mp3" to "flac". I don't use Xfce but the Bulk Renamer in Double Commander file manager functions similarly. Double Commander is quite light and useful for other tasks as well.
Thx sunrat. This seems to work OK.
(If you strip the (e.g.) .mp3 extension from the listed filenames in the text file, there is no need to rename the output files)
I've been using puddletag for audio file tagging.
It seems less intrusive than Easytag but lacks a file renaming function, so far as I can see.

User avatar
sunrat
Administrator
Administrator
Posts: 6457
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 472 times

Re: SOLVED Re: Renaming files in directory A with filenames in directory B

#6 Post by sunrat »

dauddaud1 wrote: 2021-07-22 10:45(If you strip the (e.g.) .mp3 extension from the listed filenames in the text file, there is no need to rename the output files)
Good idea. You could add another pipe to sed to do it with a single command then:

Code: Select all

ls |grep mp3 | sed s/.mp3//g > filenames.txt
I've been using puddletag for audio file tagging.
It seems less intrusive than Easytag but lacks a file renaming function, so far as I can see.
What do you mean by "intrusive"? I've used Easytag for many years and once you get used to its quirks it is ... easy! :D
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

dauddaud1
Posts: 4
Joined: 2012-10-21 21:38

Re: SOLVED Re: Renaming files in directory A with filenames in directory B

#7 Post by dauddaud1 »

<<snip>>
[/quote]
What do you mean by "intrusive"? I've used Easytag for many years and once you get used to its quirks it is ... easy! :D
[/quote]

Poor word choice? I simply meant that EasyTag seems to spend a longgggg time searching for and (?) indexing files. (I have quite a few for it to look through).

As for the quirks, well yes it was easy enough, but I succeeded with renaming the files in the first directory almost entirely without knowing at which stage the name changes are actually applied and saved. I'm still not sure - I'll bet there's a better way than trying to quit the program and saving when it complains. Anyway, it worked, thank you, and I'll persevere to see if I can make better sense of EasyTag's idiosyncracies.

User avatar
sunrat
Administrator
Administrator
Posts: 6457
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 472 times

Re: SOLVED Re: Renaming files in directory A with filenames in directory B

#8 Post by sunrat »

dauddaud1 wrote: 2021-07-22 23:45
What do you mean by "intrusive"? I've used Easytag for many years and once you get used to its quirks it is ... easy! :D
Poor word choice? I simply meant that EasyTag seems to spend a longgggg time searching for and (?) indexing files. (I have quite a few for it to look through).
Ah yes, that's one of its quirks. If you just open Easytag it will index every directory under the one you have set in Preferences for it to open initially. You can change that preference to just your music directory. The quickest way to open it is to right-click on a music file and select "Open With Easytag", then it will only index that directory and ones beneath it.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

User avatar
esp7
Posts: 177
Joined: 2013-06-23 20:31
Has thanked: 2 times
Been thanked: 4 times

Re: Renaming files in directory A with filenames in directory B

#9 Post by esp7 »

Ex Falso is more efficient if you ask me.
ThinkPad X220: i5-2520M CPU 2.5GHz - 8GB RAM 1333 MHz - SSD 860 EVO 250GB - Debian - ME_cleaned
ThinkPad X230: i5-3320M CPU 3.3GHz - 8GB RAM 1600 MHz - SSD 860 EVO 500GB - Debian - ME_cleaned

arzgi
Posts: 1193
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 31 times

Re: SOLVED Re: Renaming files in directory A with filenames in directory B

#10 Post by arzgi »

sunrat wrote: 2021-07-23 03:08
Ah yes, that's one of its quirks. If you just open Easytag it will index every directory under the one you have set in Preferences for it to open initially. You can change that preference to just your music directory. The quickest way to open it is to right-click on a music file and select "Open With Easytag", then it will only index that directory and ones beneath it.
I also used Easytag years ago, but it got so bloated, that it came unusable with my old notebooks.

I've found lltag (Debian package lltag) nice http://bgoglin.free.fr/lltag/ A cli program. Also use cmus to listen music :D

Post Reply