Single line solution:
@for %%I in ("\\path31vm\file transfers\Data Files\Inbound\VMs\su\Reg\new\*.csv") do @if not exist "%%~dpICSV\%%~nxI.completed" %SystemRoot%\System32\xcopy.exe "%%I" "%%~dpICSV\" /C /D /Q /Y >nul 2>&1
Multi-line solution:
@echo off
for %%I in ("\\path31vm\file transfers\Data Files\Inbound\VMs\su\Reg\new\*.csv") do (
if not exist "%%~dpICSV\%%~nxI.completed" (
%SystemRoot%\System32\xcopy.exe "%%I" "%%~dpICSV\" /C /D /Q /Y >nul 2>&1
)
)
Important here is the backslash at end of destination folder path because this is a clear indication for XCOPY that the target specifies a directory and not a file name. Otherwise XCOPY used here to copy a single file would prompt the user if target specifies a directory or file and waits for the input of the user. For details see batch file asks for file or folder.
For testing purposes with additional debugging information and without suppressing any standard or error output:
@echo off
for %%I in ("\\path31vm\file transfers\Data Files\Inbound\VMs\su\Reg\new\*.csv") do (
echo CSV file is: %%I
if not exist "%%~dpICSV\%%~nxI.completed" (
echo Not existing: %%~dpICSV\%%~nxI.completed
%SystemRoot%\System32\xcopy.exe "%%I" "%%~dpICSV\" /C /D /Y
) else (
echo Existing is: %%~dpICSV\%%~nxI.completed
)
)
pause
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
for /?
if /?
xcopy /?
Read also the Microsoft article about Using Command Redirection Operators.