Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Rename folder according to filename located in the folder
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
s34get
Tux's lil' helper
Tux's lil' helper


Joined: 19 Jan 2003
Posts: 76
Location: WWW

PostPosted: Thu Feb 29, 2024 8:21 am    Post subject: Rename folder according to filename located in the folder Reply with quote

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
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2021

PostPosted: Thu Feb 29, 2024 10:46 am    Post subject: Reply with quote

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
View user's profile Send private message
s34get
Tux's lil' helper
Tux's lil' helper


Joined: 19 Jan 2003
Posts: 76
Location: WWW

PostPosted: Thu Feb 29, 2024 1:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2021

PostPosted: Thu Feb 29, 2024 5:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum