Hi,
I need help in this.
i want to copy files from one directory to another. The only check is, if the file exists, it would overwrite else it would just copy. The actions should be logged in a log file with the file name.
Thank you!
copy file
Moderator: DosItHelp
Re: copy file
This (untested) code sniplet might help you:
Sidenote: You might want to change the used directories.
penpen
Code: Select all
@echo off
setlocal enableExtensions disableDelayedExpansion
>"logs\LogFile %date% %time::=%.txt" copy /Y "source\*.bat" "target"
penpen
-
- Posts: 51
- Joined: 10 Jan 2018 15:21
Re: copy file
Thank you for helping me out. Kindly suggest.
this is coping and replacing. no issues with that. I am looking for this message
Overwrite \\xxx.xlsx? (Yes/No/All): Y
1 file(s) copied.
But this shows
XXX.xlsx
XXX.xlsx
2 file(s) copied.
Thanks,
this is coping and replacing. no issues with that. I am looking for this message
Overwrite \\xxx.xlsx? (Yes/No/All): Y
1 file(s) copied.
But this shows
XXX.xlsx
XXX.xlsx
2 file(s) copied.
Thanks,
Re: copy file
I hope this "slightly" changed batch does the trick (untested):
Sidenote:
Don't run multiple instances of that skript, because then the answer file gets corrupted (overwritten) which may result in an error.
penpen
Code: Select all
@echo off
setlocal enableExtensions disableDelayedExpansion
set "filter=*.bat"
set "workDir=."
set "sourceDir=source"
set "targetDir=target"
set "logDir=logs"
set "logFile=%logDir%\LogFile %date% %time::=%.txt"
set "answerFile=%workDir%\localYes.txt"
set "fileCount=0"
for /f %%a in ('dir /b "%sourceDir%\%filter%" ^| find /v /c ""') do set "fileCount=%%~a"
set "localYes="
>nul copy /y nul "%logFile%"
for /f "tokens=2 delims=(/)" %%a in ('^<nul copy /-y nul "%logFile%"') do (
if not defined localYes set "localYes=%%~a"
)
>"%answerFile%" echo(%localYes%
for /l %%a in (1, 1, %fileCount%) do (
>>"%answerFile%" echo(%localYes%
)
>"%logFile%" (<"%answerFile%" copy /-Y "%sourceDir%\%filter%" "%targetDir%")
Don't run multiple instances of that skript, because then the answer file gets corrupted (overwritten) which may result in an error.
penpen