0

I'm trying to create a one-liner using WMI to recursively search a drive for files modified after a certain time. So far I found a line that will work for a single directory, but I was unable to figure out a way to recursively run it on every directory starting at c:\

wmic datafile where "drive='c:' and path ='\\' and lastmodified>'20140502233423.000000-240' and lastmodified<'20161223233445.000000-240'" get lastmodified, name

This returns files modified before and after those dates within the base of the c: drive

Thanks in advance.

Mofi
  • 46,139
  • 17
  • 80
  • 143
Brent
  • 1
  • 1

1 Answers1

0

You would use the LIKE operator and specify a wildcard. Eg:

wmic datafile where "drive='c:' and path like '%\\%' and lastmodified>'20140502233423.000000-240' and lastmodified<'20161223233445.000000-240'" get lastmodified, name

BE WARNED! This is hideously slow. A much better command line operation for finding files that changed after a certain date is FORFILES. EG:

FORFILES /P "C:\" /M *.* /S /C "cmd /c echo @file @fdate @ftime" /D 06/01/2016
Tim
  • 2,701
  • 3
  • 26
  • 47
  • I like the idea of using forfiles, alas it won't drill down to the time itself. A date can help though. Thanks for your help. – Brent Jul 08 '16 at 20:52
  • I was hoping I could use a for loop to recursively run the original command throughout a drive. – Brent Jul 08 '16 at 21:13
  • I can't check this at the moment, but have you tried `for /D %f in (*) do wmic datafile where "path ='%f' and lastmodified>'20140502233423.000000-240' and lastmodified<'20161223233445.000000-240'" get lastmodified, name`? If its a batch file use `%%f` instead, and [`Command Extensions`](http://ss64.com/nt/setlocal.html) should be enabled by default but its worth verifying. (Not sure you need to specify the drive) – Tim Jul 10 '16 at 00:36
  • Thanks for your help Tim. Recursion is still an issue with this command. – Brent Jul 11 '16 at 15:00
  • The biggest problem I'm having is making it a one liner. If that weren't a limitation, then you could pipe the results of `dir /b /s /a:d "C:\*"` to a text file, then [loop through the lines of that file](http://ss64.com/nt/for_f.html) and [format the string](http://stackoverflow.com/questions/5816178/how-to-replace-string-inside-a-bat-file-with-command-line-parameter-string) as needed (eg, replace `c:` with Null and each `\ ` with `\\ `). Fitting it all on one line though. (╥︣﹏᷅╥) – Tim Jul 11 '16 at 15:26