Copying a file to a new filename in each folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Copying a file to a new filename in each folder

#1 Post by stroked » 29 Aug 2013 00:19

i need a batch that copies *.nfo to folder.jpg. it needs to work from root and process each subdir.
worked fine in the subdir, but req a loop/nest to process each subdir - cd to it, do the copy, then cd back down a level.

Code: Select all

for %%a in (*.) do cd "%%a" & copy "%%~na".tbn folder.jpg & cd .. >nul


id be surprised if abve works, just thinking out loud!

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: help sought

#2 Post by Endoro » 29 Aug 2013 01:42

I made some edits....

Code: Select all

for /d /r %%a in (*) do copy "%%~fa\%%~na.tbn" folder.jpg

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: help sought

#3 Post by stroked » 29 Aug 2013 17:44

nearly bro, thnks, i removed the quotes. your snippet passes copy z:\movies\480 0-z\0-9-a-b\biss.tbn folder.jpg
which of course wont work, need copy biss\biss.tbn folder.jpg instead plse

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

Re: help sought

#4 Post by foxidrive » 29 Aug 2013 18:02

Assuming the .tbn files are in each directory:

Code: Select all

@echo off
for /d /r %%a in (*) do (
pushd "%%a"
copy *.tbn "%%~nxa.jpg"
popd
)

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: help sought

#5 Post by stroked » 29 Aug 2013 18:40

substituting %%~nxa for folder, i dont have to run to see its a diff way of achieving wat E did!, big thnks tho

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: help sought

#6 Post by stroked » 30 Aug 2013 19:04

to proceed i know what to do, but not how. is there a list of those %% anywhere
%%~fa seems to return the max absolute path avail, i want just the path of current path %cd% and one level up, not two.
what the hey is nxa?

Code: Select all

for /d /r %%a in (*) do cd %%~fa & copy %%~na.tbn folder.jpg & cd..


works but appends an extra directory on end that exists in the dir where .tbn is, so makes %%~na incorrect, make sense?

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: help sought

#7 Post by stroked » 03 Sep 2013 00:12

hmmm thought

Code: Select all

for /d /r %%a in (*) do copy %%~fa\%%~na.tbn %%~fa\folder.jpg
might work.

but output is

Code: Select all

Z:\Movies\480 0-Z\0-9-A-B>copy Z:\Movies\480 0-Z\0-9-A-B\Blood Work\extrafanart\
extrafanart.tbn Z:\Movies\480 0-Z\0-9-A-B\Blood Work\extrafanart\folder.jpg
The system cannot find the file specified.


its picking up another directory in the dir. i want to execute the instruction. prob is i dont understand the %% codes, listing?
any1 hlp plse? ta.

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: help sought

#8 Post by stroked » 05 Sep 2013 01:14

have i p****** every1 off or does noone have a solution?? if former, sorry, cant think wot ive done, but no posts for nearly a week.

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

Re: help sought

#9 Post by foxidrive » 05 Sep 2013 01:32

You didn't supply enough info about the task to make it easy to help.

Try explaining again, with directory names and the correct filenames.

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: help sought

#10 Post by stroked » 05 Sep 2013 23:02

yes fair comment, assumed to much obviously, ok then, each dir has a <dirname>.tbn [ThumBNail of cover artwork] which is just a jpg.

i wish to copy each to FOLDER.JPG in same dir as .tbn and loop to next directory.

i don't understand the %~ params, and wish to know more. ta, hth.

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

Re: help sought

#11 Post by foxidrive » 06 Sep 2013 06:55

Code: Select all

@echo off
for /d /r %%a in (*) do (
pushd "%%a"
copy "%%~na.tbn" "folder.jpg"
popd
)


Read the help in FOR /? and the last page shows the list of ~ items.

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: help sought

#12 Post by stroked » 06 Sep 2013 22:52

that worked, :D needed to remove /r switch which i assume is recursive. wanted to use xcopy, but would hang if >nul waiting for [F]ile or [D]irectory choice.
why does this occur, is there a workaround?
also it must limit the # of os, what's the cutoff, am i better to stick with COPY?
Thanks, off to do some learning...

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

Re: help sought

#13 Post by foxidrive » 07 Sep 2013 02:09

Use copy, unless you have a reason not to.

Post Reply