|
Answer» So I am looking for a way to search a C: drive through use of a batch file at the command prompt of Windows XP for all files *.doc and *.xls on a C: drive and copy them to a thumb drive.
Not sure if there is a command that can be run at the prompt to search for *.doc and *.xls on the C: and copy hits to the thumb drive at G:
This is to be used for a woman who likes to store her data everywhere on the C: drive, but wants to back it up to a thumb drive at the end of her work day for word and excel documents.
I am really picking my brain to come up with a solution since saving everything to a single folder with subfolders seems too difficult for her in which I could use an XCOPY /s/d/y from a known single main folder, and since she is in upper management I have to come up with a solution to accomodate her needs.
Anyone have any ideas on how to do this, possibly some batch snippets to lead me on the right path or a batch file to do this if its not too much of a hassle to code up quickly somehow.
Many Thanks!
Dave Have you actually tried XCOPY /S?
I suggest you give it a trial by creating a .bat file as below:
@echo off cls
ECHO A | XCOPY /S C:\*.DOC J:\BACKDOC\ > NUL ECHO A | XCOPY /S C:\*.XLS J:\BACKXLS\ > NUL
Where J: is your thumb drive
I ran the above but copied .BAT and .TXT files with no problems except I have no way of telling whether all files were copied, I don't have a record of how many .bat and .txt files there are.
(Caps are for emphasis only)
Please come back to us with your results.
Hello Dusty
I tried that batch and edited to write to C:\BACKDOC and C:\BACKXLS since I didnt have a thumb drive handy to test with, and added a pause to see the error message at the end of the routine and got an error message of:
Cannot perform a cyclic copy Cannot perform a cyclic copy Press any key to continue . . .
Not sure if this is because I am trying to write to the same drive during this copy routine. Never seen this error message before. When I get to work I will test this with a thumb drive and see if that makes everything run correctly by not trying to write to a drive that is in a read only state possibly through this instruction set.
Here is the code that I edited to test this:
@echo off cls
ECHO A | XCOPY /S C:\*.DOC C:\BACKDOC\ > NUL ECHO A | XCOPY /S C:\*.XLS C:\BACKXLS\ > NUL pause
Thanks
Dave That's an XCOPY error message which shows that XCOPY/S cannot copy from/to the same directory i.e. it cannot copy from C:\anydir to C:\anotherdir, the source and destination cannot be in the same directory. When your destination directory is J:\somedir the error condition does not exist.
Note that in this context C: is considered to be a directory altho' we may think of C: as a partition or drive letter.
Here is a MS Technet article on the error message, altho' it mentions just Win.2k it is about the XCOPY/S error message, the same error message may be displayed if running XCOPY/S in real Dos mode. The error condition should not arise when you are XCOPY'ing to your thumb drive.
Hello Dusty,
I tried this using a thumb drive and your correct that the error message goes away. I found a thumb drive at HOME before going to work and ran the batch on my home system which has a 40GB HD and I saw activity on the thumb drive, but didnt see any files copied across to it. After it ran for about 45 minutes with a blank shell window with no error messages, I terminated the batch and will try it out here in a few minutes to see if it does what it should. I should have checked the folder on the thumb drive to see if it grabbed data or not.
I will test it and see if it grabs all data as intended. For the fact that it was taking a while on my home system and the drive is 35GB full of the 40GB, it was LIKELY overwhelmed with how much it had to search through.
Before looking to batch code as a solution I also looked to see if I could find a way to run the windows search feature through the command shell and a switch to specify the search criteria, but figured it was easiest to go the path of an actual batched instruction set.
I was also curious thinking about how I should handle if there was more than one file found with the same name such as in her archive folders. You wouldnt want just only the latest sales.doc or .xls file copied to the thumb drive and the archive data not POPULATING over, so I should also add a test routine of IFEXIST rename the file or create a new folder for it so it doest stump on top of the older files on the thumb drive that are grabbed prior to the latest file date/time stamp.
Thanks,
DaveQuote I saw activity on the thumb drive, but didnt see any files copied across to it. The reason for not seeing any display of files copied is > NUL which is suppressing output to your monitor. If you want to see what's being copied delete this from both lines.
QuoteI was also curious thinking about how I should handle if there was more than one file found with the same name such as in her archive folders. Xcopy/s creates a directory system on your thumb drive which mirrors the directory system on C: so that a file which resides in C:\Sales_files\October\First_Week will be copied to J:\Sales_files\October\First_Week, so any file duplication in different directories is irrelevant.
Try running the bat then have a look at the thumb drive to see what's been done.
Note that your bat Xcopies all occurrences of .doc and .xls files and the ECHO A piped command means that you are not asked to approve overwriting on your thumb drive so that the second and subsequent runnings of the bat can be unattended. Date/time stamping can certainly be used to xcopy only the latest and greatest.
Once you have implemented your backup system I suggest you then test your backup files. Nothing worse than needing your backed-up files only to find you cannot access them - it happens HEY your correct!
It does copy the folders structures over only if a xls or doc is tied to the end of the tree as XCOPY would do.
Thanks Again!!!
The user is VERY HAPPY with this band aid to their bad habit of storing data everywhere !!!!
DaveThanks for getting back with your result..
Quotesince she is in upper management I have to come up with a solution to accomodate her needs If you get a big fat bonus for this I expect my share via Western Union... LOL
Good luck
|