Page 1 of 1

Need a batch file please

Posted: 27 Mar 2012 23:13
by almulder
Ok i don't really do batch files, but i know they can be used for many things. And now the need has arrived for the need of one.

i need a file to run and check a folder and all sub folders and look for a file and if that file is there make a copy of it but with a different name, but if that file already is there then skip it and continue on.

I have alot of movies on a server with a folder.jpg inside each folder and need to make a copy of that file but labled poster.jpg for another meda box to be able to use it. so i will need bot files there and as i add movies i will need to run this programs every so often to fill in the missing files.

example here is where my movies are stored

"M:\ServerFolders\MKV Movies HD"
then they are broken down into A, B, C ,.... folders and then each movie is in its sub folder.

example
M:\ServerFolders\MKV Movies HD\0-9\300

with in this folder i have the folder.jpg file and need a copy of it and renamed to poster.jpg so in the end i will have both a folder.jpg and a poster.jpg file in each movie folder.


I could really use your help to write (What i have been told is a simple batch file but have no idea how to write one)

THANKS!

Re: Need a batch file please

Posted: 28 Mar 2012 03:53
by foxidrive
Try this. If it looks to be copying the file, which is only echoed to the screen atm, then remove the echo and pause commands and run it again to perform the copys.

Code: Select all

@echo off
pushd "M:\ServerFolders\MKV Movies HD"
for /f "delims=" %%a in ('dir folder.jpg /b /s') do (
if not exist "%%~dpa\poster.jpg" echo copy /b "%%a" "%%~dpa\poster.jpg"
pause
)
popd

Re: Need a batch file please

Posted: 28 Mar 2012 06:09
by dbenham
Another option. Basically the same but using a different form of FOR

Code: Select all

@echo off
for /r "M:\ServerFolders\MKV Movies HD" %%F in (folder.jpg) do (
  if not exist "%%~dpF\poster.jpg" copy /b "%%F" "%%~dpF\poster.jpg"
)


Dave Benham

Re: Need a batch file please

Posted: 28 Mar 2012 06:54
by foxidrive
for /d has bugs in some cases when specifying a path and I think for /r shares them.

Re: Need a batch file please

Posted: 28 Mar 2012 09:33
by almulder
Thanks so much guys. I will check it out when I get home later today

Re: Need a batch file please

Posted: 28 Mar 2012 14:44
by almulder
ok i think i might have an issue. The file is a hidden file that we are looking for so it does not find it. Is there a way to still make this work?

Re: Need a batch file please

Posted: 28 Mar 2012 15:25
by almulder
OK i think i have found a back door way oof doing it, but i am sure there is an easier way.

here is what i did.



@echo off
pushd "M:\ServerFolders\MKV Movies HD"
for /f "delims=" %%a in ('dir /a:h folder.jpg /b /s') do (
ATTRIB -h "%%~dpa\folder.jpg"
if not exist "%%~dpa\poster.jpg" echo copy /b "%%a" "%%~dpa\poster.jpg"
ATTRIB +h "%%~dpa\folder.jpg"
pause
)
popd

is there a simple way of doing this?

Re: Need a batch file please

Posted: 29 Mar 2012 00:07
by foxidrive
That will work fine.

Re: Need a batch file please

Posted: 30 Mar 2012 10:05
by almulder
Thanks again for your help here. Yep everything worked just the way i needed.