Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Missing something - option to tell it where to save  (Read 3104 times)

0 Members and 1 Guest are viewing this topic.

zero_defekz

    Topic Starter


    Starter

    Missing something - option to tell it where to save
    « 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?)

    mat123



      Hopeful

      Thanked: 16
      • Yes
      • Yes
      • Yes
    • Experience: Familiar
    • OS: Windows XP
    Re: Missing something - option to tell it where to save
    « Reply #1 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%:\



    zero_defekz

      Topic Starter


      Starter

      Re: Missing something - option to tell it where to save
      « Reply #2 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

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Missing something - option to tell it where to save
      « Reply #3 on: May 04, 2010, 08:02:48 PM »
      and what are you entering in the prompt given by set /p?
      I was trying to dereference Null Pointers before it was cool.

      zero_defekz

        Topic Starter


        Starter

        Re: Missing something - option to tell it where to save
        « Reply #4 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

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Missing something - option to tell it where to save
        « Reply #5 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.



        I was trying to dereference Null Pointers before it was cool.

        The Raddish



          Rookie

          Re: Missing something - option to tell it where to save
          « Reply #6 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