Ctrl + C and Ctrl + V is the easiest thing that a person can do in computers , but I had the most difficult copy scripts to run. (Well ... I better have an good explanation for wasting so much time in copying stuff over ;P)
I had to copy files from one server to another over different domains ... phew. Thank God that it is over. Writing a simple copy did not help, I used XCOPY. I thought why not share my experience with all, and what better place to share than this.
To write a copy script one must keep few things in mind...
- Keep it simple
Destination is not mandatory , if you don't give it then it will copy to the current folder from where you are running the script.
- Keep every thing in Quotes
Make sure that your source and destination are in quotation marks. That will save you from the horror of not knowing what went wrong. Spaces in the file name or file path can cause xcopy to think that the 2nd part is the destination :(
- echo f
Microsoft does provide you with the convenient option of using /i . But what if you don't want it to default it to Directory and reply as file instead? Imagine how annoying it can be when you have to enter 'f' continuously. That's the last thing how you want to start your day doing. Echo f cam to my rescue. Start the xcopy with echo f | so that when the command prompt asks you if it is a file or directory it gets the answer f , that is file.
Now you can look at the errors.
A simple example :
echo f | xcopy "A\B\c.txt" "X\y\z.txt"
- Can't find it
- Need a Log??
Now you can look at the errors.
A simple example :
echo f | xcopy "A\B\c.txt" "X\y\z.txt"
Comments
Post a Comment