View previous topic :: View next topic |
Author |
Message |
s34get Tux's lil' helper
Joined: 19 Jan 2003 Posts: 76 Location: WWW
|
Posted: Thu Feb 29, 2024 8:21 am Post subject: Rename folder according to filename located in the folder |
|
|
Dears,
I'd like to rename all folders in a movie directory using a script or similar. The date should be kept and the name should come from the file located in the folder, "some_nice_movie.mp4" or "another_movie.mkv". So "./rip20210101/Stardust.1994.mkv" should be "./Stardust.1994/Stardust.1994.mkv" after the script ran. Any help appreciated.
Thank you! |
|
Back to top |
|
|
Goverp Advocate
Joined: 07 Mar 2007 Posts: 2021
|
Posted: Thu Feb 29, 2024 10:46 am Post subject: |
|
|
My "doall" script might be able to do this - something like:
Code: | doall -i 'mv ./rip*/*.mkv ./$2/$2.mkv' |
I recommend using the interactive -i or pretend -p modes until you are happy it won't do something unexpected.
<edited to include the URL for the script! >
<edited again to remove a spurious ". Note the use of single quotes in the code is mandatory> _________________ Greybeard |
|
Back to top |
|
|
s34get Tux's lil' helper
Joined: 19 Jan 2003 Posts: 76 Location: WWW
|
Posted: Thu Feb 29, 2024 1:19 pm Post subject: |
|
|
thanks, that will probably help already. Although the only option to keep the timestamp in that case is something like
Code: |
timestamp=$(stat -c %y foldername)
mv foldername new_foldername
touch -d "$timestamp" new_foldername
|
|
|
Back to top |
|
|
Goverp Advocate
Joined: 07 Mar 2007 Posts: 2021
|
Posted: Thu Feb 29, 2024 5:42 pm Post subject: |
|
|
Apparently (i.e. I've not tested it)
Code: | cp -al "$oldname" "$newname"
unlink "$oldname" |
will also do the job, once edited for your use case. _________________ Greybeard |
|
Back to top |
|
|
|