Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to select files by date in batch  (Read 2081 times)

0 Members and 1 Guest are viewing this topic.

jeff.digabel

  • Guest
How to select files by date in batch
« on: December 27, 2006, 02:24:57 PM »
For ms-dos
I ve got a folder with multiple identical file named by numeric way (1 to 98 for example). The file 98  is the newest, and i want to copy these one and only these one. The problem is, if a newer file is add, the file name will be 99. So i want a batch file which could copying the newest file in a folder.
Thanks for your help.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: How to select files by date in batch
« Reply #1 on: December 28, 2006, 05:39:30 AM »
Easiest way would be to sort the files descending by date and skim off the top entry:

Code: [Select]
@echo off
for /f %%i in ('dir *.* /tc /o:d /a-d /b') do (
      copy %%i targetdirectory
      goto tag
      )
:tag      

You may have to add path information to suit your environment. Replace targetdirectory to meet your specs.

Hope this helps. 8-)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

jeff.digabel

  • Guest
Re: How to select files by date in batch
« Reply #2 on: December 28, 2006, 08:07:13 AM »
perfect thanks a lot