Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robocopy - File names with an Ampersand

So I have a pretty basic batch script that looks at an incoming folder and based on file type moves files where I want them. Now folders that show up with "&" in them break it. How do you go about fixing this? I couldn't find an obvious answer online.

robocopy.exe "%location%" "%destination%" /E /tee /LOG+:C:\Users\etc\Log.txt

EDIT 2:

OK thanks to the comments bellow and a bunch of trail and error I figured that it was a quotation issue. Now after a bunch of trial and error found a combination of quotes and no quotes that worked, I have no idea why though. If some one is able to explain why this works and other combinations didn't I would appreciate it haha...batch is so weird.

Input -> Test.bat "C:\etc\etc\" - Path in quotes

set location=%1 - No Quotes

set type="%~2" - Quotes

set destination="C:\Users\xxxx\Desktop\Destination" - Quotes

set logfile="C:\Users\xxxx\Desktop\robolog.txt" - Quotes

robocopy.exe %location% "%destination%" /E /tee /LOG+:%logfile% - Source with no quotes but destination in quotes???

Do quotes cancel each other out? I'm confused why adding quotes would make it not work, but only work in some cases? Also having %~1 vs %1 vs "%1" vs "%~1" produced different results.

like image 356
urbanrider Avatar asked Jan 13 '23 18:01

urbanrider


1 Answers

I tested this:

@ECHO OFF &SETLOCAL
SET "location=this & that"
SET "destination=more & more"
robocopy.exe "%location%" "%destination%" /E /tee /LOG+:"%destination%\Log.txt"

And I got no error:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------

  Started : Wed Jul 31 09:59:55 2013

   Source : C:\TEST\this & that\
     Dest : C:\TEST\more & more\

    Files : *.*

  Options : *.* /TEE /S /E /COPY:DAT /R:1000000 /W:30 

------------------------------------------------------------------------------

------------------------------------------------------------------------------

                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         1         0         1         0         0         0
    Files :        81        81         0         0         0         1
    Bytes :    28.3 k    28.3 k         0         0         0         0
    Times :   0:00:00   0:00:00                       0:00:00   0:00:00

    Speed :              184585 Bytes/sec.
    Speed :              10.562 MegaBytes/min.

    Ended : Wed Jul 31 09:59:55 2013
like image 81
Dany Bee Avatar answered Jan 28 '23 18:01

Dany Bee