1.

Solve : Copy file by date?

Answer»

Hi All,
I did a search but was unable to find what I was looking for so here goes a post...

I want to copy a single file from a folder with over 100 files. The NAME of the files change and all I want is the newest file. This file will be no older than 30 mins.

I tried to use ROBOCOPY /maxage:1 but that goes back 24 hours.

Any ideas? And thanks for the help!

I should add that I am very new to batch files. Please type slow....

Here ya go:

Code: [Select]for /f "delims=" %%a in ('dir /OD /b c:\directoryA\directoryB') do set newest=%%a
copy %newest% c:\yourdirectory

The directoryA and directoryB are just stand-ins for whatever directories your files are in. Just put in the correct path in these spots. If there is a space in any part of the path, such as: C:\documents and settings\my files then be sure to put quotations around the path.
eg:
Code: [Select]for /f "delims=" %%a in ('dir /od /b "c:\documents and settings\my files"') do set newest=%%a
copy %newest% "c:\your directory"
Note that there is still an apostraphe after the quotation mark in the first line.Great! I am going to give it a try. Thanks so MUCH for your help.

Thanks! It worked! Sort of...I am trying to use this on 2 jobs. One folder has nothing but files and it grabs the newest file from the server and copies it to my MACHINE. Perfect...just what I wanted...

The other JOB has a folder and a few sub folder as well as a bunch of files. When I run it on this folder is tries to go though all the sub folders as well as the files so I am getting 2 files back. One from the bunch of files in the parent folder and one from one of the child folders.

Do you know of a why to stop it from looking though the sub folders?

Thanks again for your help!
Post your code so I can see where the hiccup is.



Discussion

No Comment Found