0

I want to use xcopy on a network path. I actually do.

The problem is that I wanted to use an /exclude option. But the file would be in a network path. But the network path has spaces (s:\my path).

So this is what I'm using and it's working right now without /exclude (S: is a mapped network file):

xcopy "S:\TI\My Path" "C:\Path" /S /I /D /Q /Y

I've tried adding an /exclude file locally and it works fine (figured out I must use the 8.3 name):

xcopy "S:\TI\My Path" "C:\Path" /S /I /D /Q /Y /exclude:c:\MyConf~1\cfg.txt

But the same didn't work when I move to a network path. I think the main reason is that network path doesn't have a 8.3 name according to dir /x.

xcopy "S:\TI\My Path" "C:\Path" /S /I /D /Q /Y /exclude:s:\MyConf~1\cfg.txt

Impossible to read the file: s:\MyConf~1\cfg.txt

The line above was translated by me from Brazilian Portuguese and may not be exactly what xcopy returns. But I think you get it.

I've tried to use a not mapped version, which is not practical actually and didn't work.

xcopy "S:\TI\My Path" "C:\Path" /S /I /D /Q /Y /exclude:\\server\MyConf~1\cfg.txt

Is there a way I can achieve this with xcopy? Is there any equivalent who does not need an install in every PC?

1 Answers1

0

I figured out a not so elegant solution with help of an idea the user S. Brottes gave me in the comments.

I found a code to see the full UNC path associated with the letter here and made some changes.

My code finds the full UNC path of the letter I've already had mapped (in this case s:) gets the full UNC path and concatenates.

After that I map it to an unused letter and use it in the exclude parameter:

@REM Get the full UNC path, maps it to a letter, use the letter in the exclude parameter and exludes the mapped letter
cls

@set _NetworkPath= @set _newLetterDrive=y

@REM finds the complete network path mapped to s: @pushd "s:"

@for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr /i "%CD:~0,2%"') do @(set _NetworkPath=%%i%CD:~2%)

@REM concatenates the actual network path with the added folder I need @REM @echo. Debug info %_NetworkPath%

@set _newPath="%_NetworkPath%TI\My configs"

@REM maps deep into the folder to a known not used letter net use %_newLetterDrive%: %_newPath%

@REM finally call the xcopy with the exclude file pointed out directly by y: @REM @echo Debug info %_newPath%

xcopy "S:\TI\My Path" "C:\Path" /S /I /D /Q /Y /exclude:%_newLetterDrive%:\cfg.txt

@REM removes the used letter net use %_newLetterDrive%: /delete /yes