Computing.Net > Forums > Programming > Batch Copy File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Copy File

Reply to Message Icon

Name: XPUser
Date: April 15, 2007 at 13:26:35 Pacific
OS: XP PRO
CPU/Ram: Intel/1 G
Product: Dell
Comment:

Greetings,

I am new to batch programming and need some expert help. Here is what I would like to do:
1. Check if an external USB HD is present. Shows up as "E:". If not there, post message and exit bat file.
2. Copy My Documents and all sub folders to a new directory on E which is named Backup on Todays Date (something like 4-15-2007).
3. Copy some selected folders like Favorites to the new folder on E.
3. Copy some specific files to the new folder on E:

I think XCOPY is the right command to use based on a lot of reading, however, the rest is not clear to me.

Thanks in advance for your kind help!



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: April 16, 2007 at 02:38:09 Pacific
Reply:

The script below may be a starting point, try it then add the XCopy for files and folders you need to backup

@Echo Off
Echo.
If exist E:\ (
Echo. External USB HD ready for BackUp
) else (
Echo. No External USB HD detected & Goto :EOF)
Echo.
Set ToDay=%Date:~-4,4%-%Date:~-10,2%-%Date:~-7,2%
XCopy "C:\Documents and Settings\%UserName%\My Documents" E:\BackUp_%ToDay% /I /E /S
XCopy "C:\Documents and Settings\%UserName%\Favorites" E:\BackUp_%ToDay% /I /E /S
Set ToDay=
::END_OF_BATCH

For the ToDay date format I prefer YYYYMMDD as this is more suitable for a progressive storage.


0

Response Number 2
Name: Eddieduce
Date: April 16, 2007 at 13:27:15 Pacific
Reply:

How can this be modified to automatically backup to different folders based of name of the week, existing folders Monday-Saturday, based on the default windows date format?

Eddieduce


0

Response Number 3
Name: IVO
Date: April 16, 2007 at 14:16:21 Pacific
Reply:

With batch scripts you can do *almost* everything, assuned it is worth of it.

Now NT batch language is lacking of builtin date/time mathematics, so relaying upon its raw arithmetics leads to cumbersome and unhandly code.

Last but not least, the date format is counry dependent and not directly suitable to be part of folders/filenames (the / separator is a forbidden character).

So stated what you want can be achieved, but I don't follow you on that lane, more I warn you to go on: be sure, I know what I'm speaking about.


0

Response Number 4
Name: XPUser
Date: April 22, 2007 at 08:25:21 Pacific
Reply:

IVO,

I have been away, however, your file works perfectly! Thanks again!!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Comapring DLL/executable ... Need VB Script help



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch Copy File

Batch - Copy Files using .txt List www.computing.net/answers/programming/batch-copy-files-using-txt-list/18010.html

Batch copy files on txt file incl. subdir. www.computing.net/answers/programming/batch-copy-files-on-txt-file-incl-subdir/20053.html

batch copy file on Ping Errorlevel= www.computing.net/answers/programming/batch-copy-file-on-ping-errorlevel/18016.html