Tuesday, July 14, 2015

Batch - call another batch and have it executed

I am trying to get some batch files working.


The first one I have (which works) takes a .rar from one drive to another and give the dir same name as the files put to rar and then copy a rename.bat file to the destination.


@ECHO OFF
cd /d J:\xxx
set path=C:\Program Files\WinRAR
FOR /f "delims=" %%d IN ('DIR /B') DO md J:\xxx\%%~nd
FOR /f "delims=" %%d IN ('DIR /B') DO WinRAR a -m0 -ep -vn -v500000B "xxx\%%~nd\%%~nd.rar" "%%~fd"
cd /d J:\xxx
FOR /f "delims=" %%d IN ('DIR /B') DO copy J:\xxx\rename.bat J:\xxx\%%~nxd
EXIT

The second calls the rename.bat and executes it, but only partially works as it calls the rename.bat but does not execute only open up a new window.


@ECHO OFF
cd /d J:\xxx
for /f "delims=" %%n IN ('DIR /B') DO start J:\xxx\%%~n\rename.bat
EXIT

and the rename.bat looks like this:


for /f "Tokens=*" %%f in ('dir /l/b/a-d') do (rename "%%f" "%%f")

This one work if I just execute the files in the dir, but it would not work when called.


Anyone have any idea to make this happen as I'm lost for good ideas for now.


If it could be done in a single .bat I would love that too.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...