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

Author Topic: Using vaiables in a path  (Read 3670 times)

0 Members and 1 Guest are viewing this topic.

Tataintz

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    Using vaiables in a path
    « on: August 14, 2017, 09:32:41 AM »
    Hey guys,

    I'm starting to code in DOS and I am having some troubles with the use of variables. I wrote a code to ROBOCOPY a given file to a disk of my choosing using a variable. Here's a shortened version of my code:

    set backupdisk=G:
    robocopy c:\users\... %backupdisk%\documents\backups /E /copyall

    Every time I run it, the command prompt interprets it with a space between the variable and the rest of the path (%backupdisk% \documents\backups) so it never works,

    Does someone know what's wrong with my code? Thanks!

    Salmon Trout

    • Guest
    Re: Using vaiables in a path
    « Reply #1 on: August 14, 2017, 12:35:25 PM »
    It doesn'tt do that on my system.

    Code: [Select]
    @echo off
    set backupdisk=G:
    echo robocopy c:\users\... %backupdisk%\documents\backups /E /copyall

    Code: [Select]
    robocopy c:\users\... G:\documents\backups /E /copyall

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Using vaiables in a path
    « Reply #2 on: August 14, 2017, 01:01:05 PM »
    The space is a real character and the set statement takes everything literally. Open your code in an editor and check for a trailing space on the set statement.

    Sometimes it's the simple things,

    Sidewinder
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Salmon Trout

    • Guest
    Re: Using vaiables in a path
    « Reply #3 on: August 14, 2017, 01:06:41 PM »
    Yes. I am so used to my editor (Scite) removing trailing white space when saving I forgot it was possible. I tried it with Notepad and got the space in the variable.

    Hackoo



      Hopeful
    • Thanked: 42
    • Experience: Expert
    • OS: Windows 10
    Incremental and scheduled backup using xcopy command in batch
    « Reply #4 on: August 15, 2017, 06:46:49 AM »
    Hi  ;)
    I created this batch script for incremental and scheduled backup using xcopy command in batch.
    The first execution of this script is to configure the paths of the source and the destination. And saves them in a .cfg file and then makes a full copy for the first time.

    It creates a scheduled task to run every hour with an incremental copy (ie : only copies the new files or has been modified from the source).

    Incemental Backup.bat