Renaming files based on Folder Names

If none of the more specific forums is the right place to ask

Renaming files based on Folder Names

Postby Fluke667 » 2018-11-17 14:59

I want Rename mp4 files in my Subfolders, the filename should be same as the folder Name after renaming...

This is my Command:

ls */*.mp4 | awk -F'/' '{print "mv " $0 " ./" $1 "_" $2 }' | bash


FolderA/MovieA.mp4 >>> FolderA.mp4
FolderB/MovieB.mp4 >>> FolderB.mp4
FolderC/MovieC.mp4 >>> FolderC.mp4



But it does not work if the folder or filesnames got a Bracket or Space or other special chars, what can i do?
Fluke667
 
Posts: 4
Joined: 2018-10-14 11:04

Re: Renaming files based on Folder Names

Postby debiman » 2018-11-17 16:39

bash:
Code: Select all
for i in *.mp4; do
    mv "$i" "${PWD##*/}_$i"
done
(not tested. needs to be run inside the folder containign the videos)
User avatar
debiman
 
Posts: 3064
Joined: 2013-03-12 07:18


Return to General Questions

Who is online

Users browsing this forum: No registered users and 9 guests

fashionable