Need a batch file please

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
almulder
Posts: 5
Joined: 27 Mar 2012 23:11

Need a batch file please

#1 Post by almulder » 27 Mar 2012 23:13

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!

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

Re: Need a batch file please

#2 Post by foxidrive » 28 Mar 2012 03:53

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

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Need a batch file please

#3 Post by dbenham » 28 Mar 2012 06:09

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

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

Re: Need a batch file please

#4 Post by foxidrive » 28 Mar 2012 06:54

for /d has bugs in some cases when specifying a path and I think for /r shares them.

almulder
Posts: 5
Joined: 27 Mar 2012 23:11

Re: Need a batch file please

#5 Post by almulder » 28 Mar 2012 09:33

Thanks so much guys. I will check it out when I get home later today

almulder
Posts: 5
Joined: 27 Mar 2012 23:11

Re: Need a batch file please

#6 Post by almulder » 28 Mar 2012 14:44

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?

almulder
Posts: 5
Joined: 27 Mar 2012 23:11

Re: Need a batch file please

#7 Post by almulder » 28 Mar 2012 15:25

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?

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

Re: Need a batch file please

#8 Post by foxidrive » 29 Mar 2012 00:07

That will work fine.

almulder
Posts: 5
Joined: 27 Mar 2012 23:11

Re: Need a batch file please

#9 Post by almulder » 30 Mar 2012 10:05

Thanks again for your help here. Yep everything worked just the way i needed.

Post Reply