Jarrad
Jarrad

Reputation: 11

batch file to copy a folder containing the most recently created file

Hey guys, I'm looking for a batch file which will copy a folder and all its contents containing the most recently created file. I need it to preserve the folder name at the destination aswell. For example:

If 'c:\test\source\inhere' contains the most recent file, then i would like the 'inhere' directory and all of its contents copied to the destination, c:\test\destination\inhere.

The .bat file would ideally sit in the 'source' folder in the example above.

Thanks!

Upvotes: 1

Views: 599

Answers (1)

keiran
keiran

Reputation: 11

xcopy and if exist not exist would do everything you need eg:-

@echo off
xcopy "C:\test\inhere\*.* " c:\mirror\test\inhere\ /c /s /r /d /y /i > c:\mirror\xcopy.log

this would copy from inhere (*.* means any file extensions could be .pdf or whatever) TO IN HERE in a parent folder called mirror. The xcopy.log just writes a log file so you can check

all was successful

Upvotes: 1

Related Questions