Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Can't read file" when trying to Exclude directory in batch file

I've been stuck on this for awhile and could use some help.

I'm trying to copy a large folder from a mapped network drive (A:) onto my local PC. I also need to exclude a subdirectory on that drive path called "Images". My current code (backup.bat) is below:

cd %HOMEPATH%\Desktop\%mydate%
xcopy "A:\PROGRA~2\QuadTech" 121\ /e /EXCLUDE:"A:\PROGRA~2\QuadTech\INSPEC~1\Images\"

Error I keep getting:

enter image description here

I've tried shortening the path with "dir /x" and I am sure the path name is correct. Also note that I need quotations as there are spaces in the PATH name.

Why am I getting errors when trying to Exclude this directory??

ANSWERED

I now have my Exclude statement point to my desktop where it reads a list of strings in a txt file.

xcopy "A:\PROGRA~2\QuadTech" 121\ /e /EXCLUDE:C:\Users\QuadTech\Desktop\excldelist.txt

Txt file contents:

\Images\
like image 965
VKkaps Avatar asked May 07 '17 20:05

VKkaps


People also ask

Can't read file exclude xcopy?

Remove the double-quotes around the name of the exclude file and you should be set! For filenames with spaces, you can use the 8-character version, e.g., PROGRA~1 for Program Files .

Can xcopy exclude a directory?

You can let xcopy exclude folders or files in folder while copying from one directory to another with simple steps. Likewise, you have better choice to do exclusion during file backup or file syncing with a comprehensive tool.

How do I exclude files from xcopy?

Using /excludeList each string in a separate line in each file. If any of the listed strings match any part of the absolute path of the file to be copied, that file is then excluded from the copying process. For example, if you specify the string "\Obj", you exclude all files underneath the Obj directory.

How do I exclude a file type in Robocopy?

The most important switches in this command are the /XD which allows you to exclude folders, and /XF that you can use to exclude files. The other options are optional, but you should use these options that you should use in any standard copy process using Robocopy.


1 Answers

This is happening because the /EXCLUDE option does not specify files to exclude.

It specifies files containing lists of files to exclude.

More info by typing xcopy /?, though I am sure you know that.

(I know, I missed it too in the beginning; sometimes it is just a matter of having a second pair of eyes.)

like image 199
Mike Nakis Avatar answered Oct 20 '22 11:10

Mike Nakis