Reputation: 2651
I found the following batch script here on SE:
Batch Script - IF EXIST copy to %localappdata% error
IF EXIST "%localappdata%\foldername\filename" (COPY /Y "filename" "location")
How do I modify the script to operate on a directory full of files? I tried this but it didn't work:
IF EXIST "temp\*.*" (COPY /Y "artwork\*.*" "temp")
Upvotes: 1
Views: 7619
Reputation: 18827
You can try something like that :
@echo off
set "FolderSource=%localappdata%\FolderTest"
Set "Target=%~dp0Location"
IF Not EXIST "%FolderSource%" echo "%FolderSource%" does not exist & pause>nul & exit
If Not Exist "%Target%" MD "%Target%"
For /f "delims=" %%a in ('Dir /b /s "%FolderSource%\*.*"') Do (
IF EXIST "%Target%\%%a" ( COPY /Y "%%a" "%Target%"
) ELSE ( COPY "%%a" "%Target%"
)
)
pause>nul
Upvotes: 2
Reputation: 70923
xcopy
command includes a update switch to only copy files that are already present in the target folder.
xcopy /y /u "artwork\*" "temp"
Upvotes: 4