Results 1 to 7 of 7

Thread: batch file coding help needed

  1. #1
    RIP Peterb ik9000's Avatar
    Join Date
    Nov 2009
    Posts
    7,704
    Thanks
    1,840
    Thanked
    1,434 times in 1,057 posts
    • ik9000's system
      • Motherboard:
      • Asus P7H55-M/USB3
      • CPU:
      • i7-870, Prolimatech Megahalems, 2x Akasa Apache 120mm
      • Memory:
      • 4x4GB Corsair Vengeance 2133 11-11-11-27
      • Storage:
      • 2x256GB Samsung 840-Pro, 1TB Seagate 7200.12, 1TB Seagate ES.2
      • Graphics card(s):
      • Gigabyte GTX 460 1GB SuperOverClocked
      • PSU:
      • NZXT Hale 90 750w
      • Case:
      • BitFenix Survivor + Bitfenix spectre LED fans, LG BluRay R/W optical drive
      • Operating System:
      • Windows 7 Professional
      • Monitor(s):
      • Dell U2414h, U2311h 1920x1080
      • Internet:
      • 200Mb/s Fibre and 4G wifi

    batch file coding help needed

    ok, I'm new to this. Today I discovered XCopy. It is amazing. Now I'm trying to write a batch routine to automate backing up multiple folders from different locations. I could try and do it via vba which I can just about write in, but I thought it would be good to start learning about using the cmd line functions.

    I've got two ini files each with a list of folder paths (all in "" and separated by ; ) eg "K:\folder 1\subfolder 2";"H:\folder 3\subfolder 4" etc

    the batch file contains the following code

    cd %~dp0
    cmd /k For %%S in BackUp_SourceList.ini DO FOR %%d IN BackUp_DestinationList.ini DO Xcopy %%S %%d /S /E /D

    it doesn't work. (the second line) - error message is BackUp_SourceList.ini was unexpected at this time.

    It is supposed to take each folder path from BackUp_SourceList and copy it to BackUp_DestinationList provided the date is newer or the file doesn't already exist on the backup directory. I'm happy the /S /E /D in xcopy are correct - but I'm clearly not using the For commands properly.

    I have also tried

    cd %~dp0
    cmd /k For %%S in BackUp_SourceList.ini DO XCOPY %%S IN BackUp_SourceList.ini %%S IN BackUp_DestinationList.ini /S /E /D

    This also no good.

    Is it the way I've compiled the ini files? Should I use "; " as delimiter instead of just ";"
    Or is it the way I'm trying to use %%S for each value in the ini files?
    Or is it something else?

    Please help!
    Last edited by ik9000; 09-05-2014 at 12:20 AM. Reason: ;) was meant to show a semi colon not a smiley wink

  2. #2
    <<== UT3 Player spoon_'s Avatar
    Join Date
    Nov 2008
    Location
    London
    Posts
    2,071
    Thanks
    113
    Thanked
    139 times in 131 posts

    Re: batch file coding help needed

    Did you give Robocopy a go before? If not you might want to

    Script to "mirror" two directories (you can add as many as you want), just populate source/destination and you should be good.

    ============================================
    set backupSRC="path_to_source"
    set backupDST="path_to_destination"

    For /F "tokens=1,2,3 delims=/ " %%a in ('date /t') do set date=%%a.%%b.%%c_
    For /F "tokens=1,2 delims=:" %%a in ('time/t') do set time=Time_%%a.%%b

    set outfile="%TEMP%\%date%%time%.log"

    robocopy.exe %backupSRC% %backupDST% /MIR /COPYALL /S /E /V /XD "System Volume Information" /XA:S /R:0 /W:0 /NP /LOG:%outfile%
    ============================================

  3. #3
    <<== UT3 Player spoon_'s Avatar
    Join Date
    Nov 2008
    Location
    London
    Posts
    2,071
    Thanks
    113
    Thanked
    139 times in 131 posts

    Re: batch file coding help needed

    Looking at your code you need to have brackets around your *.ini file names like so:

    cd %~dp0
    cmd /k For %%S in (BackUp_SourceList.ini) DO XCOPY %%S IN (BackUp_SourceList.ini) %%S IN BackUp_DestinationList.ini /S /E /D

  4. Received thanks from:

    ik9000 (09-05-2014)

  5. #4
    RIP Peterb ik9000's Avatar
    Join Date
    Nov 2009
    Posts
    7,704
    Thanks
    1,840
    Thanked
    1,434 times in 1,057 posts
    • ik9000's system
      • Motherboard:
      • Asus P7H55-M/USB3
      • CPU:
      • i7-870, Prolimatech Megahalems, 2x Akasa Apache 120mm
      • Memory:
      • 4x4GB Corsair Vengeance 2133 11-11-11-27
      • Storage:
      • 2x256GB Samsung 840-Pro, 1TB Seagate 7200.12, 1TB Seagate ES.2
      • Graphics card(s):
      • Gigabyte GTX 460 1GB SuperOverClocked
      • PSU:
      • NZXT Hale 90 750w
      • Case:
      • BitFenix Survivor + Bitfenix spectre LED fans, LG BluRay R/W optical drive
      • Operating System:
      • Windows 7 Professional
      • Monitor(s):
      • Dell U2414h, U2311h 1920x1080
      • Internet:
      • 200Mb/s Fibre and 4G wifi

    Re: batch file coding help needed

    Quote Originally Posted by spoon_ View Post
    Looking at your code you need to have brackets around your *.ini file names like so:

    cd %~dp0
    cmd /k For %%S in (BackUp_SourceList.ini) DO XCOPY %%S IN (BackUp_SourceList.ini) %%S IN BackUp_DestinationList.ini /S /E /D
    I can't get this to work.

  6. #5
    RIP Peterb ik9000's Avatar
    Join Date
    Nov 2009
    Posts
    7,704
    Thanks
    1,840
    Thanked
    1,434 times in 1,057 posts
    • ik9000's system
      • Motherboard:
      • Asus P7H55-M/USB3
      • CPU:
      • i7-870, Prolimatech Megahalems, 2x Akasa Apache 120mm
      • Memory:
      • 4x4GB Corsair Vengeance 2133 11-11-11-27
      • Storage:
      • 2x256GB Samsung 840-Pro, 1TB Seagate 7200.12, 1TB Seagate ES.2
      • Graphics card(s):
      • Gigabyte GTX 460 1GB SuperOverClocked
      • PSU:
      • NZXT Hale 90 750w
      • Case:
      • BitFenix Survivor + Bitfenix spectre LED fans, LG BluRay R/W optical drive
      • Operating System:
      • Windows 7 Professional
      • Monitor(s):
      • Dell U2414h, U2311h 1920x1080
      • Internet:
      • 200Mb/s Fibre and 4G wifi

    Re: batch file coding help needed

    bump - anyone?

    So far as I can tell I'm probably using the wrong command.

    if i just had a batch file that listed multiple Xcopy it would work

    eg Xcopy Source1 Destination1
    Xcopy source2 destination2
    etc etc

    I wouldn't have to use the For Do loop. But then I would have to manually write each line and any future changes. Particularly annoying if the destination is a removable drive whose letter is not known in advance.

    At the moment I can easily get the list of source and destination folder names from a script which makes the ini files. What I can't seem to do is get the For loop to pull out the relevant chunks from the ini files. I've tried For /F but am struggling to get my head around the options and how to get it to do what I want.

    Is there a better command I could/should try using?

  7. #6
    Registered User
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    0
    Thanked
    0 times in 0 posts
    • planA's system
      • Motherboard:
      • gigabyte ga z77m-d3h
      • CPU:
      • i3
      • Memory:
      • 4gb
      • Graphics card(s):
      • ati hd6670
      • Operating System:
      • win8.1 + linux mint
      • Internet:
      • fttc

    Re: batch file coding help needed

    I'm not really a windows person, but my first thought would be is the command running in hte correct directory?

    on unix starting a new shell (which I guess the cmd /k is doing) would reset the working directory

  8. #7
    psi
    psi is offline
    Registered+
    Join Date
    Mar 2014
    Posts
    21
    Thanks
    0
    Thanked
    1 time in 1 post

    Re: batch file coding help needed

    Shouldn't it be "BackUp_SourceList.ini" in quote marks?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •