Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts

    xcopy hangs on an error

    I have this batch code which I've managed to mangle and keep getting and error about the backupdrive variable being loaded with incompatible device when the xcopy tries to run.
    Code:
    set /P drid="Enter Drive ID of output device [E, F, ...]: "
    :: VARIABLES
    set HOME=C:\Users\winuser
    set sourcedrive=C:\Users\winuser
    set backupdrive=%drid%:
    set logfile=C:\%sourcedrive%\DESKTOP\%Date%bu_log.txt
     
    echo.
    echo %Date% # # # Moving files >> %logfile%
          xcopy "%sourcedrive%" "%backupdrive%" /E /L /R /T /Y >> %logfile%
    I used the E: drive as that is where the USB drive is, and that is what it appears to be balking on. Can someone see why it is erroring? I don't normally work with batch scripts.
    Last edited by RetiredGeek; 2015-11-21 at 07:59. Reason: Added code tags

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Spark,

    The problem is the / in the date field. I modified and tested your file as follows:
    Code:
    set /P drid="Enter Drive ID of output device [E, F, ...]: "
    :: VARIABLES
    set sourcedrive=G:\BEKDocs\Transfer\*.*
    set backupdrive=%drid%:
    set filedate=%date%
    ::  Replace / in date with - 
    set filedate=%filedate:/=-%
    set logfile=G:\BEKDocs\Batch\%filedate% bu_log.txt
     
    echo.
    echo "%Date% # # # Moving files" > "%logfile%"
          xcopy "%sourcedrive%" "%backupdrive%\" /E /L /R /Y >> "%logfile%"
    This works and creates a log file named: Sat 11-21-2015 bu_log.txt

    Containing:

    "Sat 11/21/2015 # # # Moving files"
    G:\BEKDocs\Transfer\VBA - Excel - Format Table from Raw Data by locating break column.xlsm
    G:\BEKDocs\Transfer\VBA - Excel - Limit Usage to Count.xlsm
    G:\BEKDocs\Transfer\VBA - Excel - Using Regular Expressions.xlsm
    3 File(s)


    Note: I also deleted the /T switch as this does not copy files!
    You'll also have to remove the /L switch to actually copy the files!!!

    HTH
    Last edited by RetiredGeek; 2015-11-21 at 09:14.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,179
    Thanks
    47
    Thanked 983 Times in 913 Posts
    Nice use of substitution. Not seen it used much - at all - so it might be worth an explanation. (What was that comment by BATcher about documentation?)

    cheers, Paul

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Paul,

    You're a hard task master!

    You mean this:
    Code:
    ::  Replace / in date with - 
    set filedate=%filedate:/=-%
    Didn't count?

    Here's a good reference on batch file string manipulation.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,396
    Thanks
    445
    Thanked 404 Times in 376 Posts
    Quote Originally Posted by RetiredGeek View Post
    Great website! Brings back tons of memories.

Posting Permissions

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