Batch File Assistance

jstevens
GoldLounger
Posts: 2630
Joined: 26 Jan 2010, 16:31
Location: Southern California

Batch File Assistance

Post by jstevens »

I would like to know if it is possible to do the following in a batch file. For each return of "i" a new window would be created thus copying the files for 600*.xls, 601*.xls, 602*.xls and so forth.

I know how to copy the files all though one window but would like to break up the routine to be more efficient.

Code: Select all

For i = 0 to 9
   
   Copy 60i*.xls to Destination

Next i
Thanks,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Batch File Assistance

Post by HansV »

I'm not sure what you mean by "a new window" here and why a new window would be more efficient...

The batch file equivalent of your loop would be

for /L %%i in (0,1,9) do copy "c:\sourcefolder\60%%i*.xls" "c:\targetfolder\"
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2630
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Batch File Assistance

Post by jstevens »

Hans,

A new window would be benificial as each series such as 600*.xls or 601*.xls can have anywhere between 1 and 99 Excel files.

Having a seperate window to copy the files of each series will complete in less time then just letting run in one copy routine. I'm copying files from a server to my computer via a VPN connection.

Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Batch File Assistance

Post by HansV »

I don't know how to spawn new command processors. Perhaps our batch file expert John Gray will know whether this is possible, and if so, how.
Best wishes,
Hans

User avatar
Leif
Administrator
Posts: 7209
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Batch File Assistance

Post by Leif »

I don't think it will work any better, but you could try creating one batch file that calls 10 others:
CopyAll.bat:

Code: Select all

Copy0.bat
Copy1.bat
.....
Copy9.bat
and Copy0.bat:

Code: Select all

Copy 600*.xls to Destination
Copy1.bat:

Code: Select all

Copy 601*.xls to Destination
etc.

By definition, if you create a loop as in your first example, it will have to finish each variable before it can start on the next.
Leif

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Batch File Assistance

Post by John Gray »

I'm also not sure how much quicker multiple command processors would be sending data down the same VPN line - no doubt something you can test! The difficulty with this approach is keeping track of what is going on, what has worked and what hasn't.

You could look at the START /? command to spawn new command processes(s). It is worth including a title (even if null, as in START "" ...) because problems can occur if this is absent. Also do not specify the /WAIT parameter, which will serialise executions of new command processors.

Personally I would look at ROBOCOPY as a much better replacement for COPY, with adequate logging, the downside being a plethora of parameters (but not as many as XXCOPY). If you were on Windows 7 or Windows Server 2008 I would suggest using
/MT[:n] :: Do multi-threaded copies with n threads (default 8). n must be at least 1 and not greater than 128.
but the XP010 version of ROBOCOPY which runs on XP doesn't have this facility, and you can't get the newer version to work on XP, sadly...

Ask again if you want!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
pmatz
StarLounger
Posts: 71
Joined: 20 Feb 2010, 10:31
Location: UK

Re: Batch File Assistance

Post by pmatz »

HansV wrote:I'm not sure what you mean by "a new window" here and why a new window would be more efficient...

The batch file equivalent of your loop would be

for /L %%i in (0,1,9) do copy "c:\sourcefolder\60%%i*.xls" "c:\targetfolder\"

For me this doesn't work.

If I replace the double %% to a single % (%i) then it's fine.
thanks, Paul.

User avatar
pmatz
StarLounger
Posts: 71
Joined: 20 Feb 2010, 10:31
Location: UK

Re: Batch File Assistance

Post by pmatz »

oops. just realised you need the %% for the batch program! lol. still, a new skill... looping in bat files. thanks!
thanks, Paul.

jstevens
GoldLounger
Posts: 2630
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Batch File Assistance

Post by jstevens »

John,

I am using RoboCopy (XP version) and just copying those files that have changed. Unfortunately there are a few series with 99 files. My thought was to process these with in groups of 10 such as in 6011*.xls, 6012*.xls and 6013*.xls.

I currently have 10 main batch files and it appears that I may just have to end up with 100 of them.

Thanks again for your suggestion,
John
Regards,
John

User avatar
Leif
Administrator
Posts: 7209
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Batch File Assistance

Post by Leif »

jstevens wrote:I currently have 10 main batch files and it appears that I may just have to end up with 100 of them.
Perhaps you could write a (looping) batch file that creates the 100 'sub' batch files, and then runs them?
Leif

jstevens
GoldLounger
Posts: 2630
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Batch File Assistance

Post by jstevens »

Leif,

That is most likely what I will end up with.

Thanks to all for contributing,
John
Regards,
John

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Batch File Assistance

Post by John Gray »

jstevens wrote:I am using RoboCopy (XP version) and just copying those files that have changed. Unfortunately there are a few series with 99 files. My thought was to process these with in groups of 10 such as in 6011*.xls, 6012*.xls and 6013*.xls.
I'm still not really clear about the conditions for which you are doing the copies, and the range of possible filenames.

Do all the source files live in the same directory, and are they all being copied to the same target directory?

You presumably have set up RoboCopy to copy only the changed files (however defined!).

If I assume that you have ten 'series' of spreadsheets whose filenames are of the form:
6010*.xls
6011*.xls
6012*.xls
6013*.xls
6014*.xls
6015*.xls
6016*.xls
6017*.xls
6018*.xls
6019*.xls
you could handle these in one RoboCopy, as

Code: Select all

set source="C:\source"
set target="D:\target"
set parms=601*.xls /copyall /s /np /r:0 /w:0
robocopy %source% %target% %parms% > C:\somewhere\robolog.txt
If you wanted to create one RoboCopy for each of the above series, I would do something like

Code: Select all

for /l %%a in (0,1,9) do (
  start "" robocopy c:\source d:\target 601%%a*.xls^
  /copyall /s /np /r:0 /w:0 /log:c:\somewhere\robolog%%a.log
)
(the ^ at the end of the line means to continue the next line on the same line, if you see what I mean!). You get ten RoboCopy logs to look through.

That should give you some ideas; do say if you need any further info. Your RoboCopy parameters may vary (YRPMV)!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

jstevens
GoldLounger
Posts: 2630
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Batch File Assistance

Post by jstevens »

John,

Thank you for your suggestion. I'll give it a try.

Regards,
John
Regards,
John

jstevens
GoldLounger
Posts: 2630
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Batch File Assistance

Post by jstevens »

John,
John Gray wrote:
If you wanted to create one RoboCopy for each of the above series, I would do something like....
I tested your code and it appears to be doing what I would like with one exception. I removed the "/np" thinking I would be able to display the % of file being copied in each window but the window only displays the name of the log file.

Any suggestion as to how I can get the name of the file and % of file being copied to display?

Thanks,
John
Regards,
John

jstevens
GoldLounger
Posts: 2630
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Batch File Assistance

Post by jstevens »

After a little bit more tinkering, I was able to display the file name and % of the file being copied.

It appears the one can either write to a file or display the files being copied; not both. I simply removed the name of the log file and I was able to see the files being copied.

Regards,
John
Regards,
John

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Batch File Assistance

Post by John Gray »

Yes, you're right - you can't do both (unless you include a Windows implementation of TEE), but with lots of files copied I prefer to look at the results at my leisure. I'm glad what you came up with is satisfactory!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...