Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 678  / 1 Year ago, fri, december 2, 2022, 6:23:02

I'm trying to rename my movie collection. All of the files are currently named using dots instead of spaces, i.e. Men.in.Black.avi. I want to replace all of the dots with spaces which isn't terribly difficult, but I need to preserve the last dot for the file extension, i.e. .avi, .mp4, .ogg, etc.



My Googling has provided no solutions. I'm also a Javascript developer and could see some snazzy applications for it. So, any suggestions?


More From » rename

 Answers
1

One way would be to use the Perl rename utility. The Perl regex .(?=.*.) matches a dot only when there is another dot later.



rename 's/.(?=.*.)/ /g' *.*.*


If you want to act on files in subdirectories as well:



shopt -s globstar    # you can put this in your ~/.bashrc
rename 's/.(?=.*.)/ /g' **/*.*.*


This works assuming you don't have dots in your directory names. Otherwise I think the simplest method would be to use find:



find -depth -name '*.*.*' -exec rename 's/.(?=.*.)/ /g' {} +


Alternatively, using zsh (this only renames regular files and leaves directory names alone, due to the glob qualifier (.) at the end):



autoload zmv    # you can put this in your ~/.zshrc
zmv -Q '(**/)(*.*)(.[^.]##)(.)' '$1${2//./ }$3'

[#34805] Saturday, December 3, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ainsbeave

Total Points: 280
Total Questions: 98
Total Answers: 105

Location: Faroe Islands
Member since Sat, Aug 20, 2022
2 Years ago
;