Jump to content

view files by modified date


Recommended Posts

Posted

I have a folder with thousands of files and at least 100 folders. How can I

list all of them that have been modified in the last say 60 days, sorting by

date. The dir *.* /s /o:d sorts each folder individually, not all together

as one. If I right click on the folder and do a Search, there are so many

of them and can get them into a report.

 

Thanks in advance for all advise given...

  • Replies 5
  • Created
  • Last Reply
Guest Pegasus \(MVP\)
Posted

Re: view files by modified date

 

 

"BBW" <tkarpowski@bennettcompany.com> wrote in message

news:urch0HdYIHA.4180@TK2MSFTNGP06.phx.gbl...

>I have a folder with thousands of files and at least 100 folders. How can

>I list all of them that have been modified in the last say 60 days, sorting

>by date. The dir *.* /s /o:d sorts each folder individually, not all

>together as one. If I right click on the folder and do a Search, there are

>so many of them and can get them into a report.

>

> Thanks in advance for all advise given...

>

 

Try the script below. Note that you must remove the line numbers

before you run it. You must also specify your own source folder.

Invoke the script with this command: cscript c:\BBW.vbs

 

1. Const Age = 60

2. Const Source = "D:\Temp"

3. Const TempFile = "c:\TempFile.txt"

4. Const OutFile = "c:\FileList.txt"

5.

6. WScript.Echo "Reading the file list . . ."

7. Set ObjWshShell = WScript.CreateObject("WScript.Shell")

8. Set ObjExec = ObjWshShell.exec("%ComSpec% /c dir /s " & Source)

9. Set fso = CreateObject("Scripting.FileSystemObject")

10. Set OutputStream = fso.CreateTextFile(TempFile)

11.

12. Do

13. line = ObjExec.StdOut.ReadLine

14. If InStr(line, " Directory of ") = 1 then dir = Mid(line, 15) & "\"

15. if instr(line, "/") > 0 then Call ProcessLine()

16. Loop Until ObjExec.StdOut.AtEndOfStream

17.

18. OutputStream.close

19. WScript.Echo "Sorting the file list"

20. Set ObjExec = ObjWshShell.exec("%ComSpec% /c sort " & TempFile & " > " &

OutFile)

21. WScript.Echo "The sorted file list is available in " & OutFile

22.

23. '======================

24.

25. Function ProcessLine()

26. D = CDate(Mid(line, 5, 10) & Mid(line, 16, 6))

27. If DateDiff ("d", D, Now) < Age Then

28. OutputStream.WriteLine Year(D) & "/" & Pad(Month(D)) & "/" &

Pad(Day(D)) _

29. & " " & Pad(Hour(D)) & ":" & Pad(Minute(D)) & " " _

30. & dir & Mid(line, 41)

31. End If

32. End Function

33.

34. Function Pad (N)

35. If N < 10 Then

36. Pad = "0" & N

37. Else

38. Pad = N

39. End If

40. End Function

Posted

Re: view files by modified date

 

I don't know VB. It is dying Type mismatch: 'CDate"

======

 

Const Age = 60

Const Source = "c:\Temp2"

Const TempFile = "j:\TempFile.txt"

Const OutFile = "j:\FileList.txt"

 

WScript.Echo "Reading the file list . . ."

Set ObjWshShell = WScript.CreateObject("WScript.Shell")

Set ObjExec = ObjWshShell.exec("%ComSpec% /c dir /s " & Source)

Set fso = CreateObject("Scripting.FileSystemObject")

Set OutputStream = fso.CreateTextFile(TempFile)

 

Do

line = ObjExec.StdOut.ReadLine

If InStr(line, " Directory of ") = 1 then dir = Mid(line, 15) & "\"

if instr(line, "/") > 0 then Call ProcessLine()

Loop Until ObjExec.StdOut.AtEndOfStream

 

OutputStream.close

WScript.Echo "Sorting the file list"

Set ObjExec = ObjWshShell.exec("%ComSpec% /c sort " & TempFile & " > " &

OutFile)

WScript.Echo "The sorted file list is available in " & OutFile

 

'======================

 

Function ProcessLine()

D = CDate(Mid(line, 5, 10) & Mid(line, 16, 6))

If DateDiff ("d", D, Now) < Age Then

OutputStream.WriteLine Year(D) & "/" & Pad(Month(D)) & "/" & Pad(Day(D)) _

& " " & Pad(Hour(D)) & ":" & Pad(Minute(D)) & " " _

& dir & Mid(line, 41)

End If

End Function

 

Function Pad (N)

If N < 10 Then

Pad = "0" & N

Else

Pad = N

End If

End Function

 

 

"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message

news:OPX0xbeYIHA.3400@TK2MSFTNGP03.phx.gbl...

>

> "BBW" <tkarpowski@bennettcompany.com> wrote in message

> news:urch0HdYIHA.4180@TK2MSFTNGP06.phx.gbl...

>>I have a folder with thousands of files and at least 100 folders. How can

>>I list all of them that have been modified in the last say 60 days,

>>sorting by date. The dir *.* /s /o:d sorts each folder individually, not

>>all together as one. If I right click on the folder and do a Search,

>>there are so many of them and can get them into a report.

>>

>> Thanks in advance for all advise given...

>>

>

> Try the script below. Note that you must remove the line numbers

> before you run it. You must also specify your own source folder.

> Invoke the script with this command: cscript c:\BBW.vbs

>

> 1. Const Age = 60

> 2. Const Source = "D:\Temp"

> 3. Const TempFile = "c:\TempFile.txt"

> 4. Const OutFile = "c:\FileList.txt"

> 5.

> 6. WScript.Echo "Reading the file list . . ."

> 7. Set ObjWshShell = WScript.CreateObject("WScript.Shell")

> 8. Set ObjExec = ObjWshShell.exec("%ComSpec% /c dir /s " & Source)

> 9. Set fso = CreateObject("Scripting.FileSystemObject")

> 10. Set OutputStream = fso.CreateTextFile(TempFile)

> 11.

> 12. Do

> 13. line = ObjExec.StdOut.ReadLine

> 14. If InStr(line, " Directory of ") = 1 then dir = Mid(line, 15) & "\"

> 15. if instr(line, "/") > 0 then Call ProcessLine()

> 16. Loop Until ObjExec.StdOut.AtEndOfStream

> 17.

> 18. OutputStream.close

> 19. WScript.Echo "Sorting the file list"

> 20. Set ObjExec = ObjWshShell.exec("%ComSpec% /c sort " & TempFile & " > "

> & OutFile)

> 21. WScript.Echo "The sorted file list is available in " & OutFile

> 22.

> 23. '======================

> 24.

> 25. Function ProcessLine()

> 26. D = CDate(Mid(line, 5, 10) & Mid(line, 16, 6))

> 27. If DateDiff ("d", D, Now) < Age Then

> 28. OutputStream.WriteLine Year(D) & "/" & Pad(Month(D)) & "/" &

> Pad(Day(D)) _

> 29. & " " & Pad(Hour(D)) & ":" & Pad(Minute(D)) & " " _

> 30. & dir & Mid(line, 41)

> 31. End If

> 32. End Function

> 33.

> 34. Function Pad (N)

> 35. If N < 10 Then

> 36. Pad = "0" & N

> 37. Else

> 38. Pad = N

> 39. End If

> 40. End Function

>

>

Guest Pegasus \(MVP\)
Posted

Re: view files by modified date

 

Works perfectly well for me but it may trip over different

regional settings. Replace the current function ProcessLine

with this one and report what you see on the screen:

 

Function ProcessLine()

wscript.echo "***Line=" & line & "***"

wscript.echo "***String=" & Mid(line, 5, 10) & Mid(line, 16, 6) & "***"

D = CDate(Mid(line, 5, 10) & Mid(line, 16, 6))

If DateDiff ("d", D, Now) < Age Then

OutputStream.WriteLine Year(D) & "/" & Pad(Month(D)) & "/" & Pad(Day(D)) _

& " " & Pad(Hour(D)) & ":" & Pad(Minute(D)) & " " _

& dir & Mid(line, 41)

End If

End Function

 

 

"BBW" <tkarpowski@bennettcompany.com> wrote in message

news:u38pxXfYIHA.4712@TK2MSFTNGP04.phx.gbl...

>I don't know VB. It is dying Type mismatch: 'CDate"

Posted

Re: view files by modified date

 

it is now working. I had my programmer fiddle with it.

 

Thanks we got the info we needed and I am keeping this script.

 

BBW

 

=======================

 

"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message

news:e5F66vfYIHA.3696@TK2MSFTNGP03.phx.gbl...

> Works perfectly well for me but it may trip over different

> regional settings. Replace the current function ProcessLine

> with this one and report what you see on the screen:

>

> Function ProcessLine()

> wscript.echo "***Line=" & line & "***"

> wscript.echo "***String=" & Mid(line, 5, 10) & Mid(line, 16, 6) & "***"

> D = CDate(Mid(line, 5, 10) & Mid(line, 16, 6))

> If DateDiff ("d", D, Now) < Age Then

> OutputStream.WriteLine Year(D) & "/" & Pad(Month(D)) & "/" & Pad(Day(D))

> _

> & " " & Pad(Hour(D)) & ":" & Pad(Minute(D)) & " " _

> & dir & Mid(line, 41)

> End If

> End Function

>

>

> "BBW" <tkarpowski@bennettcompany.com> wrote in message

> news:u38pxXfYIHA.4712@TK2MSFTNGP04.phx.gbl...

>>I don't know VB. It is dying Type mismatch: 'CDate"

>

>

Guest Pegasus \(MVP\)
Posted

Re: view files by modified date

 

It would be nice if you posted your solution here, for the

benefit of other readers. Don't keep it to yourself!

 

 

"BBW" <tkarpowski@bennettcompany.com> wrote in message

news:%23rYNzP4YIHA.2268@TK2MSFTNGP02.phx.gbl...

> it is now working. I had my programmer fiddle with it.

>

> Thanks we got the info we needed and I am keeping this script.

>

> BBW

>

> =======================

>

> "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message

> news:e5F66vfYIHA.3696@TK2MSFTNGP03.phx.gbl...

>> Works perfectly well for me but it may trip over different

>> regional settings. Replace the current function ProcessLine

>> with this one and report what you see on the screen:

>>

>> Function ProcessLine()

>> wscript.echo "***Line=" & line & "***"

>> wscript.echo "***String=" & Mid(line, 5, 10) & Mid(line, 16, 6) & "***"

>> D = CDate(Mid(line, 5, 10) & Mid(line, 16, 6))

>> If DateDiff ("d", D, Now) < Age Then

>> OutputStream.WriteLine Year(D) & "/" & Pad(Month(D)) & "/" & Pad(Day(D))

>> _

>> & " " & Pad(Hour(D)) & ":" & Pad(Minute(D)) & " " _

>> & dir & Mid(line, 41)

>> End If

>> End Function

>>

>>

>> "BBW" <tkarpowski@bennettcompany.com> wrote in message

>> news:u38pxXfYIHA.4712@TK2MSFTNGP04.phx.gbl...

>>>I don't know VB. It is dying Type mismatch: 'CDate"

>>

>>

>


×
×
  • Create New...