Is there any way to search for files in a directory based on date? I want to find all files with created date greater than a specific date, is it possible to do it with dir
command?
dir
by itself can not filter by date, but you can parse the output of dir
using for
command. If in your country dir
prints the date in YMD format, then you only need to compare it with given date. If the order of date parts is different, then you have to use another for
command to parse the date and change it to YMD. This will display a list of files modified after 5th Februrary.
@Echo Off
for /f "usebackq tokens=1,4 skip=5" %%A in (`dir /-c`) do (
if %%A GTR 2012-02-05 echo %%A %%B
)
if
does standard string comparison, so at the end you can get additional line if summary line passes the comparison. To avoid it, you can use if %%A GTR 2012-02-05 if exist %%B echo %%A %%B
EDIT:
There is even better approach which avoids parsing of dir
output and also allows searching by time, not only by date:
@Echo Off
for /r %%A in (*) do (
if "%%~tA" GTR "2012-02-05 00:00" echo %%~tA %%A
)