Page 1 of 1
Filter DIR by Date and Time?
Posted: 19 Jul 2021 00:12
by raywood
I am getting the desired type of information with this:
Code: Select all
for /r %F in (*) do @echo %~tF %~zF %F
The only problem is, it lists all files, whereas I want only those files that have been modified since a certain date and time. I will need to figure out how to prompt for date and time, and then how to exclude files that were modified before that specified date and time.
There don't seem to be many tools that can filter by time. I think
forfiles and
xcopy are unable. It looks like PowerShell can do it, but I don't know PowerShell, and my initial forays suggest a steep learning curve.
Re: Filter DIR by Date and Time?
Posted: 19 Jul 2021 08:49
by miskox
You could use something like this:
Code: Select all
for /r %F in (*) do @echo %~tF %~zF %F|find "16. 06. 2021"
Instead of "16. 06. 2021" you could replace it with a variable you assign earlier.
Saso
Re: Filter DIR by Date and Time?
Posted: 19 Jul 2021 10:16
by raywood
Thanks for the quick reply, Saso.
I guess I could use nested conditions to test for the cutoff date and, within that date, to test for the cutoff time. But then I'm not sure if batch will do date or time comparisons for those newer than the specified date and time.
Until the day when I figure out enough PowerShell to be dangerous, I suspect my solution here is to take the output from my proposed command and semi-manually examine it in Excel.
Re: Filter DIR by Date and Time?
Posted: 19 Jul 2021 10:48
by aGerman
WMIC can do this if you really need to involve the time rather than only the date.
Code: Select all
for /f "delims=" %%i in ('wmic datafile WHERE "Drive='C:' AND Path='\\whatever\\path\\it\\is\\'" GET LastModified^,Name^|findstr /b "[0-9]"') do (
for /f "tokens=1,2* delims=. " %%j in ("%%i") do if "%%j" gtr "20210710130000" echo %%j "%%~fl"
)
Note:
- You have to specify the drive and the path separately.
- The path begins and ends with a double backslash, and all backslashes in between have to be doubled too.
- yyyyMMddHHmmss is the format you have to specify for date and time, using the 24 hours clock.
Steffen
//EDIT Nope it's more complicated. You can't initially specify the date along with the time in the WMIC command. It has to be compared later. Code updated.