Copying via batch file - Help please :)

Associate
Joined
31 Jan 2008
Posts
1,327
Location
S Wales
Its been an awful long time since I did this and I'm utterly confusing myself as usual so I was hoping someone could help me out with this.

I'm currently failing on backing up specific files (multiples) from a folder to a USB stick


So, I need to copy all files that start with the filename SAGE to a different location. The file names vary a little but are of the format SAGExx.xxx

I need to do a complete copy everytime (the amount of data is quite small)
 
Not actually near a Windows PC to test at the moment but could you not try:

Code:
@Echo Off
copy "%location%\SAGE*.*" %destination%

Something like that?

/Edit If you are going to be doing this multiple time with the same files, add a /Y flag to the end to disable the prompting of overwriting of destination files.
 
Last edited:
Personally I'd use a .vbs file (vbscript) to do it. Steeper learning curve than batch but once you get the hang of it, much, much more powerful. I'm still halfway up the curve because I rarely code more than once every couple of months these days but as a pointer, the way I'd do it in .vbs would be to create a loop checking each file in the folder for names beginning with SAGE, probably using the Mid command.
 
Personally I'd use a .vbs file (vbscript) to do it. Steeper learning curve than batch but once you get the hang of it, much, much more powerful. I'm still halfway up the curve because I rarely code more than once every couple of months these days but as a pointer, the way I'd do it in .vbs would be to create a loop checking each file in the folder for names beginning with SAGE, probably using the Mid command.

Any reason why you'd use VBS for something this simple to do in batch scripting? Just curious!
 
I'm sure batch would work perfectly well for this. But if you wanted to modify the script at a later date to do something a bit more complex, vbscript will keep your options open. That's pretty much it, plus I have some 'template' scripts that I've written in the past which would speed up the writing of it a lot. And of course keeping in practise.
Really user-preference, it's just what I'd do!

Edit: Also thinking about it, from personal experience I have the impression that vbs actually executes quicker than batch. Hardly an issue though unless doing huge numbers of files or regularly running!
 
I'm sure batch would work perfectly well for this. But if you wanted to modify the script at a later date to do something a bit more complex, vbscript will keep your options open. That's pretty much it, plus I have some 'template' scripts that I've written in the past which would speed up the writing of it a lot. And of course keeping in practise.
Really user-preference, it's just what I'd do!

Edit: Also thinking about it, from personal experience I have the impression that vbs actually executes quicker than batch. Hardly an issue though unless doing huge numbers of files or regularly running!

I do agree that VBS is a helluva lot more powerful! I've written some scripts that have done some fairly meaty work and VBS has been a star, quick and fairly powerful! Just for something this level I'd usually use batch scripting for because it's too easy to do! Guess I'm just getting lazy! :D
 
Check out Robocopy. Not sure if you can get it to only do certain files, but you can exclude/include folders so it's a possibilty. Got more options than you can shake a stick at!
 
I do agree that VBS is a helluva lot more powerful! I've written some scripts that have done some fairly meaty work and VBS has been a star, quick and fairly powerful! Just for something this level I'd usually use batch scripting for because it's too easy to do! Guess I'm just getting lazy! :D

Heh I just remembered my backup scripts are batch! I haven't got round to rewriting them in vbs, I see your point!

Check out Robocopy. Not sure if you can get it to only do certain files, but you can exclude/include folders so it's a possibilty. Got more options than you can shake a stick at!

+1 Robocopy, much more advanced than xcopy! (which you should really use instead of copy btw)
 
Back
Top Bottom