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

    How to fix xcopy

    I wrote a backup script for batch. Works except for the XCOPY
    command. I have compared against other such script and do not see the cause for the problem.
    The following is verified:
    dest=E:/buTOP/Desktop (Note:buTOP pre-exists on flash drive)
    source=C:/Users/<username>/Desktop

    The command used for testin is:
    xcopy %inID%:%source% %dest% /E /F /I /J /K /R /S /V /Y 1>NUL

    It produces this error: File not found - Desktop
    Any help?

  2. #2
    Silver Lounger
    Join Date
    Mar 2014
    Location
    Forever West
    Posts
    2,078
    Thanks
    0
    Thanked 259 Times in 248 Posts
    Quote Originally Posted by spark55 View Post
    I wrote a backup script for batch. Works except for the XCOPY
    command. I have compared against other such script and do not see the cause for the problem.
    The following is verified:
    dest=E:/buTOP/Desktop (Note:buTOP pre-exists on flash drive)
    source=C:/Users/<username>/Desktop

    The command used for testin is:
    xcopy %inID%:%source% %dest% /E /F /I /J /K /R /S /V /Y 1>NUL

    It produces this error: File not found - Desktop
    Any help?
    The one thing I always had a problem with in batch files was remembering that all path statements to file and Folders on the HDD had to use the backslash \, not the forward slash / as used in switches and the Internet.

  3. #3
    4 Star Lounger
    Join Date
    Jan 2010
    Location
    Fort McMurray, Alberta, Canada
    Posts
    565
    Thanks
    51
    Thanked 70 Times in 68 Posts
    So I have a couple of comments, at least.

    To the error in question. XCopy requires a file specification on the source and you haven't provided one. You've only provided a folder. My recommended fix would be:

    source=C:\Users\<username>\Desktop\*.*
    Note that I've incorporated Berton's comment as well (folder delimiters should be backslashes). Some environments allow you to substitute one for another but it can be a minefield doing that, IMO.

    I'm also baffled by your use of the %inID% variable. By appending a colon on this you are indicating a drive. However the variable %source% already contains a drive. Windows should error out if you specify "Drive:Drive:". The only conceivable valid use of this form I can think of would be a UNC name. However your syntax doesn't conform to UNC rules either.
    Last edited by RetiredGeek; 2016-02-04 at 19:40. Reason: Added NOPARSE tags

  4. #4
    4 Star Lounger
    Join Date
    Jan 2010
    Location
    Fort McMurray, Alberta, Canada
    Posts
    565
    Thanks
    51
    Thanked 70 Times in 68 Posts
    LOL!

    Recursive LOL! It's emojis, emojis all the way down!!

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

    When using strings with colons in them it is best to enclose them in noparse tags :

    noparsetags.PNG

    I fixed your post above.

    HTH
    Last edited by RetiredGeek; 2016-02-05 at 16:08.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. The Following User Says Thank You to RetiredGeek For This Useful Post:

    BHarder (2016-02-11)

  7. #6
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Thanks 4 the input!!
    In fact the forward slashes were a consequence of having to type rather than cut/paste from the command screen and are/were backslashes. Sorry 4 mis info.
    The %inID% variable was a hang over which is now removed.
    source=C:\Users\<username>\Desktop
    with a proper username for <username>.
    and
    dest=E:\buTOP\Desktop
    when rerun with the correction :
    Code:
    xcopy %source%  %dest%  /E /F /I /J /K /R /S /V /Y  1>NUL
    it produces:
    Invalid drive specification.
    Any help now??

  8. #7
    Silver Lounger
    Join Date
    Mar 2014
    Location
    Forever West
    Posts
    2,078
    Thanks
    0
    Thanked 259 Times in 248 Posts
    A couple of thoughts:
    Does the subFolder of Desktop already exist in E:\buTOP\?
    Does having a backslash after Desktop make any difference? [dest=E:\buTOP\Desktop\]

  9. #8
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    1,729
    Thanks
    148
    Thanked 156 Times in 149 Posts
    Does the username have a space in it? Thus:

    C:\Users\fred bloggs\Desktop

    If so it may need double quotes around it (I think)

  10. #9
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,411
    Thanks
    447
    Thanked 406 Times in 378 Posts
    Also, I'm not sure if this matters, but I would put spaces at the end:

    Put 1 > NUL rather than 1>NUL

  11. #10
    Silver Lounger wavy's Avatar
    Join Date
    Dec 2009
    Location
    ny
    Posts
    2,383
    Thanks
    235
    Thanked 147 Times in 136 Posts
    What is the 1>nul ?? supposed to do ??

    What does :echo %source% %dest%
    pause
    return if put in the head of the batch file?
    David

    Just because you don't know where you are going doesn't mean any road will get you there.

  12. #11
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    David,

    1 is one of the standard output streams. It is standout or the standard output stream which is to the screen.
    > nul redirects it to the Null device effectively silencing the bat file with the exception of errors.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  13. The Following User Says Thank You to RetiredGeek For This Useful Post:

    wavy (2016-02-10)

  14. #12
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,411
    Thanks
    447
    Thanked 406 Times in 378 Posts
    Try running the following, to see what will happen:

    xcopy %source% %dest%

    In other words, simplify the command, for troubleshooting purposes.

    Before doing that, open a command prompt and type SET <ENTER> to make sure that your environment variables are correctly set.

  15. #13
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by wavy View Post
    What does :echo %source% %dest%
    pause
    return if put in the head of the batch file?
    David,

    Sorry I missed that on the first post.

    The command Echo to the screen the expanded command: Xcopy %source% %dest% and then pause execution until you press a key.

    e.g. if source is set to C:\Test.Dat and dest is set to X:\TransferFile\*.*

    You should see:
    Copy C:\Test.Dat X:\TransferFile\*.*
    Press any key to continue . . .
    on your screen.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  16. #14
    Silver Lounger wavy's Avatar
    Join Date
    Dec 2009
    Location
    ny
    Posts
    2,383
    Thanks
    235
    Thanked 147 Times in 136 Posts
    Quote Originally Posted by RetiredGeek View Post
    David,
    It is standout or the standard output stream which is to the screen.
    HTH
    Thanks RG
    Ah, I wonder if I knew that and forgot.
    David

    Just because you don't know where you are going doesn't mean any road will get you there.

  17. #15
    Silver Lounger wavy's Avatar
    Join Date
    Dec 2009
    Location
    ny
    Posts
    2,383
    Thanks
    235
    Thanked 147 Times in 136 Posts
    Quote Originally Posted by RetiredGeek View Post
    David,

    Sorry I missed that on the first post.

    The command Echo to the screen the expanded command: Xcopy %source% %dest% and then pause execution until you press a key.

    e.g. if source is set to C:\Test.Dat and dest is set to X:\TransferFile\*.*

    You should see:
    Copy C:\Test.Dat X:\TransferFile\*.*
    Press any key to continue . . .
    on your screen.

    HTH
    That was a question to the OP to check what is actually stored in those variables. Thanks any way
    David

    Just because you don't know where you are going doesn't mean any road will get you there.

Posting Permissions

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