Reputation: 1977
I'm trying to copy multiple files from a UNC path if a certain file does not exist in the destination directory.
SET DEST=\\ServerName\TestReleases\My Database\FolderName
if not exist "%DEST%\sqlpackage.exe" (xcopy "%DEST%\SqlPackageBinaries\*.*" "%DEST%" /S /V /I /R /Y)
%DEST%\SqlPackageBinaries\
exists and does contain files I needed.
But I got
File not found - *.*
0 File(s) copied
I also tried
SET DEST=\\ServerName\TestReleases\My Database\FolderName
if not exist "%DEST%\sqlpackage.exe" (xcopy "%DEST%\SqlPackageBinaries\" "%DEST%" /S /V /I /R /Y)
SET DEST=\\ServerName\TestReleases\My Database\FolderName
if not exist "%DEST%\sqlpackage.exe" (xcopy "%DEST%\SqlPackageBinaries" "%DEST%" /S /V /I /R /Y)
SET DEST="\\ServerName\TestReleases\My Database\FolderName"
if not exist "%DEST%\sqlpackage.exe" (xcopy "%DEST%\SqlPackageBinaries\*.*" "%DEST%" /S /V /I /R /Y)
But none of above works. I think it has something to do with the UNC but don't know what would be the correct syntax.
So it's kind of stupid that my major problem actually is the source should not be %DEST%\SqlPackageBinaries\
but \\ServerName\TestReleases\My Database\SqlPackageBinaries\
.
And to be honest, I copy the command from another section of the code and modified the content that I didn't really look into the meaning of each parameter like /S
as you mention. I simply assume that would be something like do not prompt or overwrite if the file exists.
Upvotes: 0
Views: 2490
Reputation:
Always enclose your set
command variable and value in double quotes, as in my example. Then, although xcopy
is still available on windows devices, it has been deprecated. Use robocopy
instead:
@echo off
set "dest=\\ServerName\TestReleases\My Database\FolderName"
if exist "%dest%\sqlpackage.exe" goto :EOF
robocopy "%dest%\SqlPackageBinaries" "%dest%"
Upvotes: 2