I need to copy newest file from one folder to another folder where i need to validate like if the file is same in the both folder then i should not copy the file.

suresh Thippani
suresh Thippani used Ask the Experts™
on
I have two folders folder A and folder B .now from folder A  we need to pick the newest file and copy it to folder B   and we need to validate the files like if the new file picked and the file existing in folder B are same then we should give warning message. using batch script.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Tahir QureshiSystem Analyst

Commented:
Stuart DrydenAutomation solutions architect & senior technical support engineer

Commented:
Do you have to use Windows Batch?  Some basic PowerShell would be far easier.
End-user support
Commented:
This does it.
Make a .bat file of this.

- Change the variable values of FolderA, FolderB, and FNLog to your needs.
- This .bat is in test mode. To run it for real, remove the ECHO on line 18.
- In addition, a log of results is sent to file FNLog.

@echo off
setlocal enabledelayedexpansion

REM I have two folders folder A and folder B.
REM From folder A we need to pick the newest file and copy it to folder B.
REM If the new file picked and the file existing in folder B are same then 
REM we should give warning message.

set FolderA=C:\local\test\EE\src
set FolderB=c:\local\test\EE\tgt
set FNLog=c:\local\test\EE\log.txt

pushd %FolderA%
for /f %%D in ('dir /b /a-d /o-d "%FolderA%"') do (
  if exist "%FolderB%\%%~nxD" (
    >> "%FNLog%" echo %date% %time% "%FolderB%\%%~nxD" exists
  ) else (
    copy /y "%%~fD" "%FolderB%\%%~nxD"
    >> "%FNLog%" echo %date% %time% !errorlevel! copy result of "%FolderB%\%%~nxD"
  )
  REM pause
  goto :eof
)
popd

Open in new window

NVITEnd-user support

Commented:
Question answered.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial