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?
相关问题
- What is the best way to do a search in a large fil
- Date with SimpleDateFormat in Java
- Does specifying the encoding in javac yield the sa
- String Manipulation with case sensitivity
- VBA local timezone adjustment
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- What is the complexity of bisect algorithm?
- MYSQL: How can I find 'last monday's date&
- Calculate number of working days in a month [dupli
- Get file created date in node
- Temporal Extraction (i.e. Extract date/time entiti
- Visual Studio: Is there an incremental search for
- Postgres String to Date EXAMPLE 10Apr77 to 10/04/1
Just discovered the
forfiles
command.Will list all the log files modified more than seven days old, in all subdirectories, though it does not appear to look at the create date. It does support specifying a specific date.
See
forfiles /?
for more info.dir
by itself can not filter by date, but you can parse the output ofdir
usingfor
command. If in your countrydir
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 anotherfor
command to parse the date and change it to YMD. This will display a list of files modified after 5th Februrary.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 useif %%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:Well you cant as far as i know, but this sort of think will work, but still really useless unless you have a short date range ;)
This is easy to do with PowerShell. I know that your question was about cmd, but PS is included in windows 7 and later. It can also be installed on XP and Vista.
Use the
Get-ChildItem
command (aliased asdir
) to get all files. Pipe the output to theWhere-Object
command (aliased as?
) to return files where the date is greater then (-gt
) a specific date.For Powershell 2.0 (default on Windows 7), you must use a scriptblock:
For Powershell 3.0 (default on Windows 8) and up you can use this simpler syntax instead:
The
dir -file
command returns a collection ofSystem.IO.FileInfo
objects. This file object has many properties that you can use for complex filtering (file size, creation date, etc.). See MSDN for documentation.an easier way for me is something like