Help With batch file

Hi,

Im wanting to create a batch file that takes the first directory in the structure, uses it as a variable, check to see if there is a file in that directory, then copy it to another directory.

At the moment we use a batch like this:

copy 001\HTML\BINV-MON-001.HTM   001\DOWNLOAD\BINV-MON-001.HTM
copy 333\HTML\BINV-MON-333.HTM   333\DOWNLOAD\BINV-MON-333.HTM
copy 407\HTML\BINV-MON-407.HTM   407\DOWNLOAD\BINV-MON-407.HTM
copy AKKF\HTML\BINV-MON-AKKF.HTM   AKKF\DOWNLOAD\BINV-MON-AKKF.HTM
copy BEER\HTML\BINV-MON-BEER.HTM   BEER\DOWNLOAD\BINV-MON-BEER.HTM
copy BME\HTML\BINV-MON-BME.HTM   BME\DOWNLOAD\BINV-MON-BME.HTM
copy BST\HTML\BINV-MON-BST.HTM   BST\DOWNLOAD\BINV-MON-BST.HTM
copy CHAR\HTML\BINV-MON-CHAR.HTM   CHAR\DOWNLOAD\BINV-MON-CHAR.HTM
copy CJLL\HTML\BINV-MON-CJLL.HTM   CJLL\DOWNLOAD\BINV-MON-CJLL.HTM
copy CSGS\HTML\BINV-MON-CSGS.HTM   CSGS\DOWNLOAD\BINV-MON-CSGS.HTM
copy HOLL\HTML\BINV-MON-HOLL.HTM   HOLL\DOWNLOAD\BINV-MON-HOLL.HTM
copy JOR\HTML\BINV-MON-JOR.HTM   JOR\DOWNLOAD\BINV-MON-JOR.HTM
copy LAIT\HTML\BINV-MON-LAIT.HTM   LAIT\DOWNLOAD\BINV-MON-LAIT.HTM
copy LINK\HTML\BINV-MON-LINK.HTM   LINK\DOWNLOAD\BINV-MON-LINK.HTM
copy MOUK\HTML\BINV-MON-MOUK.HTM   MOUK\DOWNLOAD\BINV-MON-MOUK.HTM
copy NPFX\HTML\BINV-MON-NPFX.HTM   NPFX\DOWNLOAD\BINV-MON-NPFX.HTM
copy PMON\HTML\BINV-MON-PMON.HTM   PMON\DOWNLOAD\BINV-MON-PMON.HTM
copy PSTN\HTML\BINV-MON-PSTN.HTM   PSTN\DOWNLOAD\BINV-MON-PSTN.HTM
copy QEXP\HTML\BINV-THU-QEXP.HTM   QEXP\DOWNLOAD\BINV-THU-QEXP.HTM
copy RAYA\HTML\BINV-MON-RAYA.HTM   RAYA\DOWNLOAD\BINV-MON-RAYA.HTM
copy SMS\HTML\BINV-MON-SMS.HTM   SMS\DOWNLOAD\BINV-MON-SMS.HTM

now i want the batch file to go through and read the first directory put it in a variable eg. curdir="001". Then i want it to go and check to see if the html file is there, if it is there i then want to copy it to the %curdir\DOWNLOAD\  directory, then move on to the next directory in the structure and do the same thing.
can any one help me with this?
LVL 5
Anthony_EAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
This should do the trick if I understand what your asking for.  The following is the command you would use if you do NOT put this in a batch file.  If you put this in a batch file, make sure to change all %a references to %%a

for /f "tokens=1" %a in ('dir /ad /b') do @if exist %a\HTML\BINV-MON-%a.HTM copy %a\HTML\BINV-MON-%a.HTM %a\DOWNLOAD\BINV-MON-%a.HTM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony_EAuthor Commented:
Thanks leew!!, worked like a charm

just 1 more thing, how can i get it to echo what file is being copied as its going through the process?

ive got:
for /f "tokens=1" %%a in ('dir /ad /b') do @if exist %%a\HTML\BINV-MON-%%a.HTM copy %%a\HTML\BINV-MON-%%a.HTM %%a\DOWNLOAD\BINV-MON-%%a.HTM

do i add it at the end by putting a & there or what? like &echo %aa\HTML\BINV-MON-%%a.htm COPIED?
0
Lee W, MVPTechnology and Business Process AdvisorCommented:
I'd probably do this:
for /f "tokens=1" %%a in ('dir /ad /b') do @if exist %%a\HTML\BINV-MON-%%a.HTM copy %%a\HTML\BINV-MON-%%a.HTM %%a\DOWNLOAD\BINV-MON-%%a.HTM & Echo %aa\HTML\BINV-MON-%%a.htm COPIED

Or to log the copies,

for /f "tokens=1" %%a in ('dir /ad /b') do @if exist %%a\HTML\BINV-MON-%%a.HTM copy %%a\HTML\BINV-MON-%%a.HTM %%a\DOWNLOAD\BINV-MON-%%a.HTM & Echo %aa\HTML\BINV-MON-%%a.htm COPIED > copy.log
0
Anthony_EAuthor Commented:
thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.