Listing and opening files with filename selection filter

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
d360991
Posts: 8
Joined: 18 Mar 2012 13:12

Listing and opening files with filename selection filter

#1 Post by d360991 » 12 Nov 2012 20:40

Folks,

In a particular folder, I have a collection of files with dates as prefixes in the filenames. E.g.:

20121024 - file1.txt
20121028 - file2.jpg
20121112 - file3.docx
20121114 - file4.txt
20121127 - file5.xlsx

I would like to open only those files that have as prefix a date that is today or before. For instance, in the above set, I would like my batch file to launch the first three files and ignore the other two.

How would I write a script to do this?

Thank you very much,
-Roger

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Listing and opening files with filename selection filter

#2 Post by Aacini » 12 Nov 2012 21:21

Assuming that the format displayed by DATE command is MM/DD/YYYY:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
for /F "tokens=1-3 delims=/" %%a in ("%date%") do set today=%%c%%a%%b
for %%a in (*.*) do (
   set fileName=%%a
   set fileDate=!fileName:~0,8!
   if !fileDate! gtr %today% goto exitLoop
   start "" !filename!"
)
:exitLoop

Post Reply