Filter DIR by Date and Time?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
raywood
Posts: 3
Joined: 20 Jan 2020 20:28

Filter DIR by Date and Time?

#1 Post by raywood » 19 Jul 2021 00:12

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.

miskox
Posts: 397
Joined: 28 Jun 2010 03:46

Re: Filter DIR by Date and Time?

#2 Post by miskox » 19 Jul 2021 08:49

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

raywood
Posts: 3
Joined: 20 Jan 2020 20:28

Re: Filter DIR by Date and Time?

#3 Post by raywood » 19 Jul 2021 10:16

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.

aGerman
Expert
Posts: 4195
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Filter DIR by Date and Time?

#4 Post by aGerman » 19 Jul 2021 10:48

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.

Post Reply