|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#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 |
|
|
|
|
|
#2 |
|
Member (14 bit)
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.
|
|
|
|
|
|
#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.
|
|
|
|
|
|
#4 |
|
Ride 'em Cowboy
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 |
|
|
|
|
|
#5 |
|
Member (14 bit)
Premium Member
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. |
|
|
|
|
|
#6 | |
|
Member (9 bit)
Join Date: Mar 2001
Location: Illinois
Posts: 352
|
Quote:
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 |
|
|
|
|
|
|
#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. |
|
|
|
|
|
#8 | |
|
Member (14 bit)
Premium Member
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
|
Quote:
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\*.* |
|
|
|
|
|
|
#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? |
|
|
|
|
|
#10 |
|
Ride 'em Cowboy
Join Date: Dec 1999
Location: Dallas, Tx
Posts: 9,109
|
DOS can't handle the space in New Files....
|
|
|
|
|
|
#11 | |
|
Member (14 bit)
Premium Member
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
|
Quote:
md "test folder" and it created the folder named test folder |
|
|
|
|
|
|
#12 |
|
Forum Administrator
Staff
Premium Member
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. |
|
|
|
|
|
#13 |
|
Member (14 bit)
Premium Member
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. |
|
|
|
|
|
#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:
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. |
|
|
|
|
|
|
#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!
|
|
|
|
|
|
#16 |
|
Member (3 bit)
|
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. |
|
|
|
|
|
#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:
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! |
|
|
|
|
|
|
#18 |
|
Forum Administrator
Staff
Premium Member
Join Date: May 2000
Location: Joplin MO
Posts: 37,791
|
Try "Documents and Settings"\Larry\...............
|
|
|
|
|
|
#19 | |
|
Member (9 bit)
Join Date: Mar 2001
Location: Illinois
Posts: 352
|
Did you mean like this?
Quote:
Sharing Violation |
|
|
|
|
|
|
#20 |
|
Forum Administrator
Staff
Premium Member
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/? |
|
|
|
|
|
#21 | |
|
Member (9 bit)
Join Date: Mar 2001
Location: Illinois
Posts: 352
|
Quote:
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? |
|
|
|
|
|
|
#22 |
|
Forum Administrator
Staff
Premium Member
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 / |
|
|
|
|
|
#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. |
|
|
|
|
|
#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? |
|
|
|
|
|
#25 |
|
Member (14 bit)
Premium Member
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 |
|
|
|
|
|
#26 | ||
|
Member (9 bit)
Join Date: Mar 2001
Location: Illinois
Posts: 352
|
Quote:
Now if I create the "enter.txt", & save to the desktop...then run this batch Quote:
Last edited by bozo; 12-15-2004 at 07:44 AM. |
||
|
|
|
|
|
#27 | |
|
Member (14 bit)
Premium Member
Join Date: Jan 2002
Location: The Great NorthWest
Posts: 12,594
|
Quote:
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". |
|
|
|
|
|
|
#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. |
|
|
|
|
|
#29 |
|
Forum Administrator
Staff
Premium Member
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.
|
|
|
|
|
|
#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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|