Robocopy command line - file with spaces - command-line

I am trying to run the following command:
robocopy.exe \\eisdevl.nas.gatech.edu\coldfusion\devl\cfapps\cfeis\mybeap \\eisdevl.nas.gatech.edu\coldfusion\test\cfapps\cfeis\mybeap "ADMIN_HEADER.CFM" "new folder\NEW TEXT 3.TXT" /mir /log:\\eisdevl.nas.gatech.edu\coldfusion\devl\cfapps\cfei\mysync2\logs\rc_09032013_lrobinson33_1.txt /NDL /r:2 /w:2
From this I get:
Started : Wed Sep 04 09:32:22 2013
Source - \eisdevl.nas.gatech.edu\coldfusion\devl\cfapps\cfeis\mybeap\
Dest - \eisdevl.nas.gatech.edu\coldfusion\test\cfapps\cfeis\mybeap\
Files : ADMIN_HEADER.CFM
Options : /COPY:DAT /R:1000000 /W:30
ERROR : Invalid Parameter #4 : "new folder\NEW TEXT 3.TXT"
Can anyone give me the correct syntax for dealing with spaces in the folder AND file name?

The ending backslash \ on the directory isn't allowed. Just specify the full path without the ending \ on it. You can use the "pathnames" in quotes just fine then.

Enclose everything in double quotes that will have spaces or other poison characters. They can also be used with short names safely.
robocopy.exe "<fromdir>" "<todir>" "file.cfm" "new file 3.cfm" /mir /log:"#path#\cfeis\mysync2\logs\rc_090313.txt" /NDL /r:2 /w:2

c:\Program" "Files
Would be the answer that worked for me.

Thanks New Guy. I had this:
robocopy "%source%\Core" "%destination%\Core" Start.br Client.br Menu.br Check File Versions.br
trying to get the four files:
Start.br
Client.br
Menu.br
Check File Versions.br
But it just wouldn't work until I tried your trick: (notice the new double quotes)
robocopy "%source%\Core" "%destination%\Core" Start.br Client.br Menu.br Check" "File" "Versions.br
Now it works great. Don't think I ever would have thought to try that befoe.

Related

How to robocopy directories with spaces AND special characters in the name

Hey there I'm running into an issue when trying to robocopy several thousand files to a destination folder that contains spaces and special characters.
Code:
robocopy "SOURCE" "\\arc\GLUONPREP\Market Centers\~1 FOR MC TEAM\Apparel Logos " *-1c.pdf /MT:64 /XX /R:1 /W:0 /S
Result:
Started : Thursday, July 29, 2021 12:04:21 PM
Source - [omitted for privacy]
Dest - C:\Users\joshh\Centers\~1\
Files : FOR
MC
Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
ERROR : Invalid Parameter #5 : "TEAM\Apparel"
I was reading that in order to handle spaces in directories, some have added a space right before the ending double quote. But I'm seeing that it might be a combination of spaces and special characters.
I've tried reading the documentation but I couldn't find anything and haven't found another question similar that has been answered or where the solution worked.
If you have a link to another article I could check out that would be great or a solution that would be extremely helpful!
Thank you!
try xcopy
xcopy /S /I /E "source path" "destination path"
for more usage of xcopy visit

How to perform two ROBOCOPY statements from one source folder to two destination folders in one batch file?

I have an interesting situation where I'd like to move some files from directory X to directory Y, but in order to MOVE the files without deleting the source folder, I created a log statement in said folder. A very simple version of what I'm doing is this:
robocopy
"C:\Desktop\Origin" "C:\Desktop\Destination"
/e /move /XF "C:\Desktop\Origin\test.log"
/log:"C:\Desktop\Origin\test.log"
This results in the moving of all files in "Origin" directory to "Destination" directory, and doesn't get rid of the "Origin" directory, as the "/e /move" flags normally would. Now, if I didn't want that log file, I could simply add this line to the code:
del "C:\Desktop\Origin\test.log"
But, I actually do want to keep this log file. I just want it somewhere else. So what I've been trying to do is to move it to directory Z with "/e /mov" or even just "/s" and then the delete. For example:
robocopy
"C:\Desktop\Origin" "C:\Desktop\Destination"
/e /move /XF "C:\Desktop\Origin\test.log"
/log:"C:\Desktop\Origin\test.log"
robocopy
"C:\Desktop\Origin" "C:\Desktop\Destination 2"
/s
del "C:\Desktop\Origin\test.log"
But after trying multiple times, with multiple little variations, nothing seems to happen. The first robocopy happens, but the second doesn't seem to happen at all. It seems like multiple robocopy statements can run in one batch file (which is what I want) but perhaps not from the same source directory. Does anyone know why this is the case and also how I can achieve my stated goal? Thanks!
Thanks to the suggestion of Ken White, I found a solution to this. If you use MOVE.EXE, it works just as expected.
robocopy
"C:\Desktop\Origin" "C:\Desktop\Destination"
/e /move /XF "C:\Desktop\Origin\test.log"
/log:"C:\Desktop\Origin\test.log"
move
"C:\Desktop\Origin\test.log" "C:\Desktop\Destination 2"
One thing to note is that you can't use /LOG+: with this method, since you'd be writing the log file to a location where no log file exists, since it had been moved previously to "Destination 2". However, even the normal log files include the *EXTRA files already in the directory.

How to use robocopy for selective file copying

I am using omake for my project build
As part of my delivery build I need to copy some delivery related files into a folder
How I can use robocopy execution where I can only copy the interested files(which are selected by running a for loop on a list I have)
Into the folder.
List_paths = filepath1
Filepath2
.
FilepathN
For file in list_paths
%exec robocopy $(file,A) $(destin)
End for
By doing that robocopy always complains me that there is no such file by adding \ at the end of eCh file and for destin folder too.
I Understand that robocopy just works fine for copying files from one folder to other but I have condition to copy only selective files from folders (for which I have the list of paths)
Please help on this.
If you have a textfile with complete patnames (i.e list.txt), with content:
d:\temp\a.sql
d:\temp\b.sql
d:\temp\c.sql
and a batchfile roboDo.bat like this:
#echo off
SET dest=d:\temp\temp\
FOR /f "useback tokens=1" %%f IN (`type list.txt`) DO (
ECHO copying %%~nxf from %%~dpf to %dest%
ROBOCOPY /NP /NJH /NJS %%~dpf %dest% %%~nxf >NUL
)
running the batchfile wil output this:
D:\TEMP>robodo
copying a.sql from d:\TEMP\ to d:\temp\temp\
copying b.sql from d:\TEMP\ to d:\temp\temp\
copying c.sql from d:\TEMP\ to d:\temp\temp\

CMD dir List video files - Not Found error

I crafted some command line code (function? I don't know the technical term, my apologies) that is meant to look in a network folder (and all it's subfolders) and only list the file path for those files that are a particular type. I tried to test it on a folder with less information in it first, however I got the error File Not Found. This confused me because I looked in the folder--there were definitely .VOB and .mp4 files in the specified folder.
When I run the code included below, I don't get the error, BUT I'm getting a bunch of files I don't want (.pdf .xml .jpeg--etc.) I think because they're system files such as the .jpeg files for the .avi thumbnails.
dir "\\nas-rb4b\projectx2" /s /b *.avi *.mov *.mp4 *.wmv *.mpg *.lnk *.ldb *.rar *.mpeg *.m4v *.vob *.zip>Projx2RERUN.txt
Can anyone help me understand why I got the File Not Found error when I tried to run the exact same code but with a different more specific folder?
I also don't know how to modify the code/function to exclude files that are not the listed file types and are not system folders. Any help is, as always, much appreciated!
Read the newest dir command reference in Windows Commands:
Syntax:
dir [<Drive>:][<Path>][<FileName>] [...] [/p] [/q] [/w] [/d] [/a[[:]<Attributes>]][/o[[:]<SortOrder>]] [/t[[:]<TimeField>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4]
Remarks:
To use multiple FileName parameters, separate each file name with a
space, comma, or semicolon.
The command in question dir "\\nas-rb4b\projectx2" /s /b *.avi *.mov *.mp4
(truncated) says and performs the following:
dir "\\nas-rb4b\projectx2" /s /b, (i.e. all files in "\\nas-rb4b\projectx2"), then
dir /s /b *.avi (i.e. all .avi files in the current directory), then
dir /s /b *.mov (i.e. all .mov files in the current directory), then
dir /s /b *.mp4 (i.e. all .mp4 files in the current directory), …
Solution (read pushd and popd reference as well):
pushd "\\nas-rb4b\projectx2"
dir /s /b *.avi *.mov *.mp4 *.wmv *.mpg *.lnk *.ldb *.rar *.mpeg *.m4v *.vob *.zip>Projx2RERUN.txt
popd
Following some advice from Ken White along with a combination of the answers given here, here, and information from here I made the expression below which eventually worked for me.
dir /b /s \\nas-rb4b\projectx2\*.avi \\nas-rb4b\projectx2\*.mov \\nas-rb4b\projectx2\*.mp4 \\nas-rb4b\projectx2\*.wmv \\nas-rb4b\projectx2\*.mpg \\nas-rb4b\projectx2\*.rar \\nas-rb4b\projectx2\*.mpeg \\nas-rb4b\projectx2\*.m4v \\nas-rb4b\projectx2\*.vob \\nas-rb4b\projectx2\*.zip
It is not pretty but it allowed me to search for multiple file types using only one expression and have their paths all sent to one txt file rather than searching each file extension individually.
So far it is working as intended.

Best way to compare some text files

Here is the simplified version of the situation I'm dealing with:
Folder Files1 containing a.txt, b.txt, c.txt
Folder Files2 containing a.txt, b.txt, c.txt
I want to find the best way to compare these files. All I need to know is which files are different. For example I need to know a.txt is different from a.txt in Files2 folder (I don't need to know what is different inside them).
Right now I load both in Notepad++ and use the compare function, but this is a pain.
I tried fc, but I'm getting cryptic output.
You could use Robocopy for that
robocopy c:\Temp\different\folder1 c:\temp\different\folder2 /e /l /ns /njs /njh /ndl /fp /log:c:\temp\whatIsDifferent.txt
Newer c:\Temp\different\folder1\b.txt
New File c:\Temp\different\folder1\d.txt
the key parameter is /L which allows you to "compare" instead of actually copying.
From Robocopy /? help
::
:: Logging Options :
::
/L :: List only - don't copy, timestamp or delete any files.
Do a dry-run (/l) with robocopy:
robocopy C:\files1 C:\files2 /njh /njs /ndl /l
/l Specifies that files are to be listed only (and not copied, deleted, or time stamped).
Rsync can be used to do this.
rsync -rvnc —delete delme/ delme2/
This will show you which files differ in the 2 directories.
See http://www.techrepublic.com/blog/linux-and-open-source/how-to-compare-the-content-of-two-or-more-directories-automatically/ for me details.