mstumpo
asked on
Selective Copy and overwrite
I have a problem where a vendor copied files and did not preserve the date and time. Some files have subsequently changed which cannot be overwritten. Essentially I am looking for a way to do the following:
If <AFILE> is dated <DATE>
copy file with same name from <SOURCE>
overwriting <AFILE>
Source and destination paths will be the same EXCEPT for Drive Letter.
Thanks in advance for any help.
If <AFILE> is dated <DATE>
copy file with same name from <SOURCE>
overwriting <AFILE>
Source and destination paths will be the same EXCEPT for Drive Letter.
Thanks in advance for any help.
ASKER
Files in the destination folder IF they have a specific date will be overwritten by the files in the source folder.
Are those all the same date, so we can't, say, copy all files that newer from the source directory as they will actually be older? Can you give us an example of what the file dates look like.
If it is a specific day, It might be worth actually making a file of all the affected files from your destination directory and then using that to copy the source files again, though could always be the case that another file was edited on that same day?
e.g. this as a batch file would collect all entries for the date that you enter into a CSV file we can work from.
We could use forfiles also to find files but that can only find files newer or older than a specified date, not exactly ON a date.
Steve
If it is a specific day, It might be worth actually making a file of all the affected files from your destination directory and then using that to copy the source files again, though could always be the case that another file was edited on that same day?
e.g. this as a batch file would collect all entries for the date that you enter into a CSV file we can work from.
@echo off
pushd c:\mystartdir
dir *.
set /p MyDate=Enter date to look for in the same format as dir listing above, e.g. dd/mm/yyyy
(for /f "tokens=*" %%A in ('dir /b /s /a-d *.*') do echo "%~fA",%~tA) > AllFiles.txt
echo The file AllFiles.txt now contains all those files
find "%MyDate% < AllFiles.txt > DatedFiles.txt
notepad DatedFiles.txt
popd
We could use forfiles also to find files but that can only find files newer or older than a specified date, not exactly ON a date.
Steve
Okay, this should do what you described. Save as a BAT file, and adjust the paths and dates near the top and give it a test.
@echo off
setlocal EnableDelayedExpansion
set SourceDir=B:\EE\EE28690499\Source
set DestDir=B:\EE\EE28690499\Dest
set CopyDate=06/18/2015
for %%A in ("%DestDir%\*.*") do (
if exist "%SourceDir%\%%~nxA" (
for %%B in ("%SourceDir%\%%~nxA") do (
set FileDate=%%~tB
if "!FileDate:~0,10!" EQU "%CopyDate%" (
echo Updating "%%~A" from "%%~B"
copy /y "%%~B" "%%~A" > NUL
)
)
)
)
~bp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or is it only one specific file name that is involved which you will also specify?
~bp