Batch Programming - Copy With X
Batch Programming - Copy With X
@echo off xcopy D:\documents\*.doc K:\documents\ /s /p /f /d:12-12-2009 pause Note here: K:\ or whatever letter it is, is your flash drive or your USB hard disk. /P expects a confirmation and an user input when a file is about to be overwritten. *.doc stands for every doc-file, all file hat have the ending .doc. You can also do this with txt files so *.txt or *.odt, if you have OpenOffice. Now this can be extended with more parameters. So, for example, there are files that need to be excluded. We dont want to copy them. This can be done with the option /exclude: @echo off xcopy D:\documents\*.doc K:\documents\ /s /p /f /d:12-12-2009 /exclude:d:exclude.txt pause
Now for this, you need to create a txt-file with your editor. Open it and type the names that you don t want to copy. Each filename has to be in a new line, so like: doc1 doc2 doc3 Give it a name and put the name like it is shown in the code above. So /exclude:pathtothefileandname.txt
You can even exclude different type of files. If you put *.odt in the txt file, just *.odt in the first line and all *.odt files will be excluded.
Now, you can also get files from a client in your LAN. If that client has got a shared folder and you want to get the files you just use xcopy to get them. Make sure you write the correct syntax for this: xcopy \\192.168.2.105\cd1\example.txt d:\ Here, 192.168.2.105 is just an example, so put the correct IP-address in there. Cd1 is the folder that is shared among the clients and example.txt is the file you want to copy. D:\ is the files destination. Xcopy \\192.168.2.105\cd1\*.* d:\ Here, *.* acts as a substitute for all files in the folder cd1. Note: Sometimes it can be useful to copy the rights and ACLs for files. Use the option /O for this.