Computer Hope

Microsoft => Microsoft DOS => Topic started by: zero_defekz on April 30, 2010, 07:25:32 PM

Title: Missing something - option to tell it where to save
Post by: zero_defekz on April 30, 2010, 07:25:32 PM
Hello.

This is my first attempt at writing a batch script, so go easy on me. lol ;D

I tested this script a few hours ago, and overall, it took about 15-20 minutes to run (~25.5 gigs of data)

As you can see, it's just a simple backup script. But, one thing that's been irking me about it (even though I'm a novice) is that I haven't found any info online (or maybe I'm just using the wrong search terms) on how I can get the script to prompt the user for a backup location.

The location that's listed (F:\Backup_%mm%-%dd%-%yyyy%\) is a local drive on my personal system. However, not everyone will have several hard drives and/or partitions to put the backup on.

With that said, lets assume that the user who runs this script, has an external drive plugged into their system. How can I get the script to prompt them for a location that they can enter?

Also, is there something I can add that will show the user the location of the backup?

For example, when the script is done, it will print out a message that says:

"Backup complete! Your backed up data is located in: X:\Backup_date_of_backup"

Thanks in advance!

Here's my script thus far:

Code: [Select]
@echo off
echo ***********************************
echo * Vinny's Data Backup Script v1.0 *
echo ***********************************
echo.
echo This script will back up your Itunes music, videos, personal photos,
echo and internet favorites into a folder labeled with todays date,
echo which you can then burn to DVD(s) or copy to an external harddrive.
echo.
pause
echo Creating folders...
Set mm=%DATE:~4,2%
Set dd=%DATE:~7,2%
Set yyyy=%DATE:~10,4%
mkdir F:\Backup_%mm%-%dd%-%yyyy%\Itunes
mkdir F:\Backup_%mm%-%dd%-%yyyy%\Pictures
mkdir F:\Backup_%mm%-%dd%-%yyyy%\Favorites
echo.
echo Done!
echo.
pause
echo Preparing to back up your Internet Bookmarks...
xcopy "%USERPROFILE%\Favorites\*.*" "f:\Backup_%mm%-%dd%-%yyyy%\Favorites\" /e
echo.
echo Preparing to backup your personal photos...
xcopy "%USERPROFILE%\My Documents\My Pictures\*.*" "f:\Backup_%mm%-%dd%-%yyyy%\Pictures\" /e
echo.
echo Preparing to backup your Itunes Library...
xcopy "%USERPROFILE%\My Documents\My Music\iTunes\*.*" "f:\Backup_%mm%-%dd%-%yyyy%\Itunes\" /e
pause

(P.S: Overall thoughts on this script?)
Title: Re: Missing something - option to tell it where to save
Post by: mat123 on April 30, 2010, 09:43:57 PM
after the first pause put

set /p dr=enter external drive letter:

and replace
F:\ with %dr%:\
Title: Re: Missing something - option to tell it where to save
Post by: zero_defekz on May 04, 2010, 07:52:51 PM
after the first pause put

set /p dr=enter external drive letter:

and replace
F:\ with %dr%:\

Thanks for your reply. However, when I added that, i get the following output:

"The filename, directory name, or volume label syntax is incorrect"
after it tries creating the folders (mkdir).

The command is written out like this:

mkdir %dr%:\Backup_%mm%-%dd%-%yyyy%\Favorites
Title: Re: Missing something - option to tell it where to save
Post by: BC_Programmer on May 04, 2010, 08:02:48 PM
and what are you entering in the prompt given by set /p?
Title: Re: Missing something - option to tell it where to save
Post by: zero_defekz on May 04, 2010, 08:04:16 PM
and what are you entering in the prompt given by set /p?

I've tried several different variations:

i
i:
i:\

and they all return the same error(s) because it's trying to create 3 folders on the drive that I specify
Title: Re: Missing something - option to tell it where to save
Post by: BC_Programmer on May 04, 2010, 08:08:01 PM
you have to enter a single letter.

try echoing %dr%:\ after you enter it and see what it expands to.



Title: Re: Missing something - option to tell it where to save
Post by: The Raddish on May 05, 2010, 09:34:21 AM
Additionally, I found a pretty neat course online that deals with writing a backup utility, and it served me as a great refresher of batch scripting since I haven't done it in over ten years.

It's put together pretty well but uses some old-school techniques.  In any case, it was worth the few hours to me to go through it and adapt the program to my needs while (re)learning to write batch scripts.

http://www.allenware.com/icsw/icswidx.htm