Welcome to TSG!
When using Xcopy and copying a directory tree, the destination can't be a subfolder of the source. While the For /r loop is returning single file names, the /T and /E switches tell Xcopy that it's copying a tree, so it gives the cyclic copy error.
You've left off the
d modifier, so there is no drive letter specified in the Destination. It will still work, but in some situations, that can give unexpected results, so best to include it: %%~
dpnI
If you remove the /E and /T switches, you'll get another prompt for each file:
Does C:\Test\filename_wgs.shp specify a file name
or directory name on the target
(F = file, D = directory)?
Xcopy was meant to copy files, not rename them. When copying single files, it expects the Destination to be a folder name ending with \. If you don't have the \, it gives the above prompt. So if you want to rename the file, there is no way to avoid the prompt.
And neither example will overwrite an existing file. If
filename_wgs.shp exists, your code will copy it to
filename_wgs_wgs.shp.
Your best bet is to use a Dir command, pipe it to Findstr to remove the folders you want to exclude, then pipe it to a 2nd Findstr to exclude files that already have the
_wgs added to their name
You then check if
filename_wgs.shp already exists, and if not, then copy the file.
This should do the trick:
Code:
Set _root=C:\Test
PushD %_root%
For /F "delims=" %%I In ('Dir /A-D /B /S *.shp^|Findstr /I /V /G:excludelist.txt^|Findstr /E /I /L /V "_wgs.shp"') Do If Not Exist "%%~dpnI_wgs.shp" Copy "%%I" "%%~dpnI_wgs.shp"
PopD If
excludelist.txt is not in the _root folder (C:\Test in this example), you'll need to specify the path to the file.
To specify a folder name in
excludelist.txt, best to use
\foldername\ format, or you may get partial matches and exclude folders you didn't intend to.
For example, if you put
folder1 in the
excludelist.txt file, it will exclude
folder1,
folder11,
folder1mustbeincluded, and
dofolder125now.
\folder1\ will only exclude
folder1.
HTH
Jerry