You are not logged in.

#1 2011-01-06 00:39:17

Lyude
Member
Registered: 2010-10-03
Posts: 20

Fix file extensions on audio files?

Alright so here's my problem: I was importing a ton of MP3/4's from a friend's iPod, and apparently Rhythmbox decided it would be better to copy them and strip every single extension (Arch recongnizes them, but I need to put them on failtunes on their Windows PC, which requires the extensions to be correct). I know very well of the file command, however there are 781 files with no extension, and doing this manually would be hell. I've looked on the repos and the AUR for a program to set the file extensions based on the file type, along with maybe a script (tried doing one in Bash but I couldn't figure out how I'd manage something like that due to the lack of regex) or the like to do so on Google, but I have had no luck. Does anyone know how I could do this?

Offline

#2 2011-01-06 00:59:03

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Fix file extensions on audio files?

in bash...

shopt -s globstar
for file in **; do
  IFS='/' read -r -d';' _ minor < <(file -bi "$file")
  [[ "$minor" = mp4 ]] && ext=mp4 || ext=mp3
  mv "$file" "$file".$ext
done

I don't believe you're going to hit the max args limit here with only 781 files.

Offline

Board footer

Powered by FluxBB