Page 1 of 1
Copying a file to a new filename in each folder
Posted: 29 Aug 2013 00:19
by stroked
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!
Re: help sought
Posted: 29 Aug 2013 01:42
by Endoro
I made some edits....
Code: Select all
for /d /r %%a in (*) do copy "%%~fa\%%~na.tbn" folder.jpg
Re: help sought
Posted: 29 Aug 2013 17:44
by stroked
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
Re: help sought
Posted: 29 Aug 2013 18:02
by foxidrive
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
)
Re: help sought
Posted: 29 Aug 2013 18:40
by stroked
substituting %%~nxa for folder, i dont have to run to see its a diff way of achieving wat E did!, big thnks tho
Re: help sought
Posted: 30 Aug 2013 19:04
by stroked
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?
Re: help sought
Posted: 03 Sep 2013 00:12
by stroked
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.
Re: help sought
Posted: 05 Sep 2013 01:14
by stroked
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.
Re: help sought
Posted: 05 Sep 2013 01:32
by foxidrive
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.
Re: help sought
Posted: 05 Sep 2013 23:02
by stroked
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.
Re: help sought
Posted: 06 Sep 2013 06:55
by foxidrive
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.
Re: help sought
Posted: 06 Sep 2013 22:52
by stroked
that worked,
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...
Re: help sought
Posted: 07 Sep 2013 02:09
by foxidrive
Use copy, unless you have a reason not to.