Go Back   PCMech Forums > Windows Support > Windows Legacy Support (XP and earlier)

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-05-2004, 08:20 AM   #1
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Simple"Copy" batch file

I am experimenting with using a batch file to directly copy files from their original location to a dedicated backup location. Here's what I have done:

In notebook I create the following file:
copy D:\bids M:\New Folder
save as a .bat file.

M:\New Folder is a newly created empty folder.
The copy does not work...am I missing a dos command to achieve this? I know this should be easy...but I'm not up to speed with dos commands.

thanks
bozo is offline   Reply With Quote
Old 12-05-2004, 08:27 AM   #2
Member (14 bit)
 
bailey's Avatar
 
Join Date: Mar 1999
Location: Christmas, Florida
Posts: 10,661
I am just courious, why do you want to do it in dos mode when it is so easy to just copy/paste any folder you want in windows.
bailey is offline   Reply With Quote
Old 12-05-2004, 08:46 AM   #3
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
I want to setup a backup batch file that I can schedule to run at night. I currently have my backup jobs done via XP's built in backup utility. I want to direct copy my data files to a dedicated partition, since they are all small enough that I don't need compression. So I would like to direct copy them without using the backup utility.
bozo is offline   Reply With Quote
Old 12-05-2004, 09:06 AM   #4
Ride 'em Cowboy
 
EzyStvy's Avatar
 
Join Date: Dec 1999
Location: Dallas, Tx
Posts: 9,109
copy D:\bids\*.* M:\New Folder

Have to tell it what to copy as well as where to copy it from. Note that this will only work once. Next time if the same files are on the M drive it's going to ask if you want to replace them.
__________________
Stand Up 2 Cancer - SU2C
EzyStvy is online now   Reply With Quote
Old 12-05-2004, 09:32 AM   #5
Member (14 bit)
Premium Member
 
TwoRails's Avatar
 
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
You may want to consider using XCOPY which as more command line options. Here's an example of one I use routinely. Note that this is an incremetal backup.

echo This will copy files to the CD RW burner
echo Press any key to continue or Ctrl-C to EXIT
pause
xcopy f:\database\Clarion5\*.* o:\Clarion5\*.* /m /s /e /h


Bailey, it really a lot easier and faster to plop in a CD-RW (or DVD+RW) and double click the batch file and let it do it's thing unattended (for the most part) and do your backups. I don't have to worry about swapping disks as, like in the example above, I have a disk for all my specific little categories. I update my checkbook, for example? Drop in the CD and click, and I'm checking email instead of drag-n-drop, or copy-n-paste.
TwoRails is offline   Reply With Quote
Old 12-05-2004, 09:51 AM   #6
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Quote:
Originally Posted by EzyStvy
copy D:\bids\*.* M:\New Folder

Have to tell it what to copy as well as where to copy it from. Note that this will only work once. Next time if the same files are on the M drive it's going to ask if you want to replace them.
OK using this command:
copy D:\Bids\*.* M:\ it will copy all the files, but not where I want them. I want then to go into a folder on the M: drive i.e. M:\New Folder
This command:
copy D:\Bids\*.* M:\New Folder
A dos window will come up for a flash of a second, then close...I presume it is errowing out, but I cannot "pause" to see what the error might be. It appears there's a problem the way I am writing the soure folder. Again the source folder is empty.

Second ??? Will the switch /Y turn off the overwrite promt for continuios overwriting?

thanks-larry
bozo is offline   Reply With Quote
Old 12-05-2004, 10:01 AM   #7
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Using xcopy this command:
xcopy D:\Bids\*.* M:\New Folder
I still have the dos window up very briefly, but I was able to get the error
"Invalid number of parameters"...nothin is coppied.
bozo is offline   Reply With Quote
Old 12-05-2004, 10:09 AM   #8
Member (14 bit)
Premium Member
 
TwoRails's Avatar
 
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
Quote:
Originally Posted by bozo
OK using this command:

copy D:\Bids\*.* M:\New Folder

... but I cannot "pause" to see what the error might be....
Put the command:

Pause

as the last line in your batch file. It will pause the window so you can see what's going on.

Also, put in "*.*" after the folder name, like:

M:\New Folder\*.*
TwoRails is offline   Reply With Quote
Old 12-05-2004, 10:20 AM   #9
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
This command works
xcopy D:\Bids\*.* M:\Bids
I changed the source folder to "Bids", and the copy began first asking if M:\Bids is a "File" or "Directory"... I answered Directory...and the M:\Bids file was created & sucessfully copied, Which is A OK...I was going to rename the "New File" anyway...I just can't figure out why I could not direct it to the folder "M"\New Folder"

I also put the "/Y" switch at the end, so now it will overwrite without prompting.

Thanks for all your help!

Any other clever ideas I could pu in this batch file?
bozo is offline   Reply With Quote
Old 12-05-2004, 11:52 AM   #10
Ride 'em Cowboy
 
EzyStvy's Avatar
 
Join Date: Dec 1999
Location: Dallas, Tx
Posts: 9,109
DOS can't handle the space in New Files....
EzyStvy is online now   Reply With Quote
Old 12-05-2004, 12:04 PM   #11
Member (14 bit)
Premium Member
 
TwoRails's Avatar
 
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
Quote:
Originally Posted by EzyStvy
DOS can't handle the space in New Files....
Good catch. It can, however, if you put quotes around it. For a test, for example, at the command prompt, I typed in:

md "test folder"

and it created the folder named

test folder
TwoRails is offline   Reply With Quote
Old 12-05-2004, 12:48 PM   #12
glc
Forum Administrator
Staff
Premium Member
 
glc's Avatar
 
Join Date: May 2000
Location: Joplin MO
Posts: 37,791
1. Do not put spaces in folder names.

xcopy c:\bids\*.* m:\bids /i/y
pause

2. Do not save it as a .bat file if you have 2K or XP - save it as a .cmd file.
glc is online now   Reply With Quote
Old 12-05-2004, 05:32 PM   #13
Member (14 bit)
Premium Member
 
TwoRails's Avatar
 
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
For clarification, no, you can't use spaces in a batch file if you do not enclose them with quote marks. You can use them if they are enclosed in quotes.

Here is a batch file I just wrote and tested on a brand new (but formatted) CD-RW. It works as expected. (I put in a bunch of remarks so it will be easy to follow):

rem this is a batch file to show how to use spaces in a batch file.

rem create a new directory on the CD-RW:

md y:\"This is a new folder"


rem now copy all the files over to the new directory
rem note the use of *.* to the target directory, this saves having to answer Y or N to if the target is a file or directory:

xcopy g:\temp\*.* y:\"This is a new folder"\*.*


rem show what's in the new directory:
dir y:\"This is a new folder"\*.*


rem pause to see the results:
pause


I don't know about W2K, but XP has both the Command.com and Cmd.exe command line interpreters. Command.com is basically for backward compatibility while Cmd.exe has a lot of the same features, but adds a lot more features that are not backward compatible. In otherwords, the above file runs just fine as a .bat file as it uses commands that Command.com understands. It also runs fine with the .cmd extention in my test. If the file were to use any Cmd.exe commands not supported by Command.com, then it won't run. Since all my .bat batch files do what I want (they are just very simple), I've not learned any Cmd.exe commands so I can't give an example of what won't work.
TwoRails is offline   Reply With Quote
Old 12-06-2004, 12:54 AM   #14
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Thanks for the help...I'm enjoying learning a whole new world...but this one I am having trouble with...side note...my end goal here is to have 6 copy jobs all contained in one batch file...I have got 3 working, but this ones is a problem:
Quote:
md M:\"MyName Documents"
rem now copy all the files over to the

new directory
Xcopy D:\"MyName Documents"\*.* M:\"My NameDocuments"*.*
pause
With this batch, the directory M:\"MyName Documents" is created...it starts copying a file...then returns this result "Could not expand the second file name so as to match the first".

Secondly...It does not seem to matter whether I save as a .bat or .cmd file...when run the dos window shows a "cmd.exe" command.
bozo is offline   Reply With Quote
Old 12-06-2004, 05:19 AM   #15
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Never mind the post above...I found the problem...I forgot the "\" after the My Name Documents in the target. Duh!
bozo is offline   Reply With Quote
Old 12-06-2004, 05:33 AM   #16
Member (3 bit)
 
DiScO's Avatar
 
Join Date: Sep 2004
Location: North of the "border"
Posts: 5
Send a message via Yahoo to DiScO
I was just about to reply with that exact answer. Nice catch!

Also noticed this:
md M:\"MyName Documents"

but then below that, you put:
Xcopy D:\"MyName Documents"\*.* M:\"My NameDocuments"*.*

Your spacing for the folder is in another spot. Don't know if that was a typo or not.
DiScO is offline   Reply With Quote
Old 12-06-2004, 07:21 AM   #17
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Yes Disco...that was a typo, as I changed the real name to post.

Well I have my backup.cmd nearly complete except for this one:
Quote:
xcopy C:\"Documents and

Settings\Larry"\*.* M:\"Docs & Settings"

/y
pause
This command returns a "Sharing Violation"

Any idea as to how to make a command to copy my "Documents & Settings"

Thanks So Much to all that have helped in this project...I feel like a kid with a new toy hehe!
bozo is offline   Reply With Quote
Old 12-06-2004, 10:59 AM   #18
glc
Forum Administrator
Staff
Premium Member
 
glc's Avatar
 
Join Date: May 2000
Location: Joplin MO
Posts: 37,791
Try "Documents and Settings"\Larry\...............
glc is online now   Reply With Quote
Old 12-06-2004, 12:29 PM   #19
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Did you mean like this?
Quote:
xcopy C:\"Documents and Settings"\Larry\*.* M:\"Docs & Settings"\*.* /y
pause
This returns: "c:\Documents and Settings\Larry\ntuser.dat
Sharing Violation
bozo is offline   Reply With Quote
Old 12-06-2004, 02:59 PM   #20
glc
Forum Administrator
Staff
Premium Member
 
glc's Avatar
 
Join Date: May 2000
Location: Joplin MO
Posts: 37,791
You got a sharing violation because ntuser.dat is always in use whenever you are in Windows and it cannot be accessed to copy it. Add the /C switch to let it continue on error.

To see all the switches, open a command prompt and type xcopy/?
glc is online now   Reply With Quote
Old 12-06-2004, 03:42 PM   #21
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Quote:
xcopy C:\"Documents and Settings"\Larry\*.* M:\"Docs&Settings"\*.* /y /c
pause
Adding the "/c" switch did not make any difference...still the same "sharing violation"

I tried to see the command switches using the command prompt...If I use: xcopy/?...it says "Windows cannot find file"...If I use xcopy[space]/? the switch definitions come up very briefly then go off (to fast to see)...also tried
xcopy[space]/?/p....to see if the help file would pause, but it does not.

I'm starting to think that I may abort this method of backing up my "Documents and Settings", and stay with XP's backup utility for that file, since "ntuser.dat" is in use & can't be copied...wouldn't that render the backup useless anyway?
bozo is offline   Reply With Quote
Old 12-06-2004, 05:30 PM   #22
glc
Forum Administrator
Staff
Premium Member
 
glc's Avatar
 
Join Date: May 2000
Location: Joplin MO
Posts: 37,791
Are you using command or cmd? You should be using cmd.

It's /y/c - no space between y and /
glc is online now   Reply With Quote
Old 12-06-2004, 05:46 PM   #23
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
MISSION Acomplished...I now have a total of 10 backup jobs all contained in my batch file, along with a disk cleanup batch at the start of the batch file. I did use XP's backup utility to create the command line for my "Documents & Settings"...then copied the command line created by the backup utility, & pasted it to the batch file...so the "Documents & Setting" backup job still uses the backup utility...I can live with that!

The entire Batch file only takes 5 minutes to run...whereas my former backup routine took 35 nimutes. The nice part about doing things this way is if I want to restore an individual file I can easily copy/paste that file, without having to run a entire backup set to retrieve a file...all the backup up files are un-compressed, and in their original file extensions. Secondly, all the backup files reside on a didicated partition, where they can easily be found for cd/w burning on a single cd.

Thanks again for everyone who replied...I got a little more knowledge with each reply...that helped me along the way!

I could post the file if anyone is interested in seeing it.

Larry

post edit: yes glc...I was saving the file as ".cmd"

Last edited by bozo; 12-06-2004 at 05:50 PM.
bozo is offline   Reply With Quote
Old 12-14-2004, 10:22 AM   #24
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
My backup batch is working very well, but I would like to add "the date the file is copied" to the batch, so I may go to the copied files & find out When they were copied, for verifacation purposes.

Any ideas on how to add that command to my batch file?
bozo is offline   Reply With Quote
Old 12-14-2004, 06:43 PM   #25
Member (14 bit)
Premium Member
 
TwoRails's Avatar
 
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
Are you meaning to just have a text file copy of the dates? If so, first make a file called:

enter.txt

Do this with a text editor, like Notepad, open a new file and do nothing but hit the enter key once. Then save the file as "enter.txt".

Then, add the line below to your batch file:

date < enter.txt >> backupdate.txt

where "backupdate.txt" is any file name you want, but it needs the .txt extention.

that will put the following lines in your backupdate.txt file:

The current date is: Tue 12/14/2004
Enter the new date: (mm-dd-yy)


You can add other text to the file by using the line below, but modifying it to your liking:

echo This is my text here >> backupdate.txt
TwoRails is offline   Reply With Quote
Old 12-15-2004, 07:42 AM   #26
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Quote:
md m:\backupdate.txt

date < d:\"Bogie Documents\enter.txt" >>

m:\backupdate.txt
pause
With this batch, I get "Access Denied"...It does create "m:\backupdate.txt" file...also [d:\"Bogie Documents\enter.txt"] is the location where I created & saved the "enter.txt" file per your instructoins.

Now if I create the "enter.txt", & save to the desktop...then run this batch
Quote:
date < enter.txt >> backupdate.txt
I get the "enter.txt" file on the desktop...and a "backupdate.txt" file on the desktop with the date as it is suppost to be...the problem comes when I try to have this same operation done, and direct them to the folder I want then in.

Last edited by bozo; 12-15-2004 at 07:44 AM.
bozo is offline   Reply With Quote
Old 12-16-2004, 08:05 PM   #27
Member (14 bit)
Premium Member
 
TwoRails's Avatar
 
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
Quote:
Originally Posted by bozo
With this batch, I get "Access Denied"...It does create "m:\backupdate.txt" file...also [d:\"Bogie Documents\enter.txt"] is the location where I created & saved the "enter.txt" file per your instructoins.

Now if I create the "enter.txt", & save to the desktop...then run this batch I get the "enter.txt" file on the desktop...and a "backupdate.txt" file on the desktop with the date as it is suppost to be...the problem comes when I try to have this same operation done, and direct them to the folder I want then in.
Sorry if I was not clear. Your example:

md m:\backupdate.txt

creates a Directory (Folder) and not a file. And then, with nothing after the ">>" in your line below:

date < d:\"Bogie Documents\enter.txt" >>

there is no "redirecting" the output of "date" to anything. The ">>" is the redirect command and the output has to go somewhere, which is why your second example:

date < enter.txt >> backupdate.txt

works and you get the text file "backupdate.txt".
TwoRails is offline   Reply With Quote
Old 12-17-2004, 06:18 AM   #28
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
Perhaps my C&P above was unclear, since the output shows in a different line above. Here is the complete line where the output should be "m:\backupdate.txt"

date < d:\"Bogie Documents\enter.txt" >> m:\"backupdate.txt"

The result is "Access Denied" with this batch.

Now if I delete the drive (m:\) from the batch like this:
date < d:\"Bogie Documents\enter.txt" >> backupdate.txt

The result is a newly created "backupdate.txt" file on my desktop showing todays date. From this I can conclude that the "enter.txt" file & location are OK.

So my problem is, I want the output file to be redirected to a folder in the "m:\" partition. It seens as any variation I try to redirect ends up in error.

Last edited by bozo; 12-17-2004 at 09:14 AM.
bozo is offline   Reply With Quote
Old 12-17-2004, 09:43 AM   #29
glc
Forum Administrator
Staff
Premium Member
 
glc's Avatar
 
Join Date: May 2000
Location: Joplin MO
Posts: 37,791
Are you logged in as administrator or as a user? Check your ownership and permissions on the M drive.
glc is online now   Reply With Quote
Old 12-17-2004, 08:33 PM   #30
Member (9 bit)
 
Join Date: Mar 2001
Location: Illinois
Posts: 352
I am loged in as an administrator. I am usure what you mean by checking ownership & permissions for the drive, but I do have 10 other backup jobs in this same batch that write to the m:\ drive in a similar fashion for example:


xcopy D:\Contracts\*.* M:\Contracts /Y
bozo is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:29 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2