Batch to recursively copy and rename files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
EvilGav
Posts: 1
Joined: 21 Jun 2013 06:23

Batch to recursively copy and rename files

#1 Post by EvilGav » 21 Jun 2013 06:31

Hoping someone here can help with this.

I'm copying my music library (or parts thereof) onto a micro-sd card to use in my Android phone. After some fiddling around, I found that in order to display the album image on the phone you need to have a JPG called "folder". The music exists as ripped with Windows Media, which creates 4 JPG files, one of which is called "folder.jpg". However, that is the lowest quality image.

Copying the entire file structure is easy enough with the XCOPY command and including the JPG files is equally a breeze. However, i'm looking for a batch the will cycle through the created folder structure and rename the largest JPG file to "folder.jpg".

Any help appreciated here!!

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch to recursively copy and rename files

#2 Post by Squashman » 21 Jun 2013 06:52

Code: Select all

for /f "delims=" %%A in ('dir /b /ad /s') DO (
PUSHD "%%A"
for /F "delims=" %%G in ('dir /b /a-d /OS *.jpg') do set largest=%%G
rename "%largest%" "folder.jpg"
POPD
)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch to recursively copy and rename files

#3 Post by foxidrive » 21 Jun 2013 07:52

Simple change - you'd have to use Move /y to overwrite the smaller file.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch to recursively copy and rename files

#4 Post by Squashman » 21 Jun 2013 08:22

foxidrive wrote:Simple change - you'd have to use Move /y to overwrite the smaller file.

Agreed.

Post Reply