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.
mstumpoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
So you only want to copy files with a last modified date of a specific day that you will specify, from the source folder to the dest folder?

Or is it only one specific file name that is involved which you will also specify?

~bp
0
mstumpoAuthor Commented:
Files in the destination folder IF they have a specific date will be overwritten by the files in the source folder.
0
Steve KnightIT ConsultancyCommented:
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.

@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

Open in new window


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
0
Bill PrewCommented:
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
      )
    )
  )
)

Open in new window

~bp
0
Bill PrewCommented:
And with a few comments to add clarity.

@echo off
setlocal EnableDelayedExpansion

REM Define folders and date to select for updating
set SourceDir=B:\EE\EE28690499\Source
set DestDir=B:\EE\EE28690499\Dest
set CopyDate=06/18/2015

REM Look at all files in the dest folder
for %%A in ("%DestDir%\*.*") do (

  REM If that file exists in source folder then check it further
  if exist "%SourceDir%\%%~nxA" (

    REM Use FOR to get access to source file's date info
    for %%B in ("%SourceDir%\%%~nxA") do (

      REM Get source file's date
      set FileDate=%%~tB

      REM Compare the date from the file (first 10 characters of date time) to desired date to copy
      if "!FileDate:~0,10!" EQU "%CopyDate%" (

        REM Dates match, display a message and copy this file
        echo Updating "%%~A" from "%%~B"
        copy /y "%%~B" "%%~A" > NUL

      )

    )

  )

)

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.