PDA

View Full Version : Solved: file list with last accessed date ....



patel
11-05-2012, 10:52 AM
with attached code I can have a file list, how can I have also
Creation, Last Access, Last Written date ?
Sub filelist()
With CreateObject("wscript.shell")
c1 = Split(.exec("cmd /c dir D:\test\*.* /b /s /ta /o-n").stdout.readall, vbCrLf)
End With
LV = UBound(c1) + 1
Range("A2:A" & LV) = WorksheetFunction.Transpose(c1)
End Sub

snb
11-05-2012, 11:01 AM
Sub filelist()
With CreateObject("wscript.shell")
sn = Split(.exec("cmd /c dir D:\test\*.* /b /s /o-n").stdout.readall, vbCrLf)
End With
cells(2,1).resize(ubound(sn)+1) = WorksheetFunction.Transpose(sn)
End Sub

How to retrieve properties of closed files; see

http://www.snb-vba.eu/VBA_Bestanden_en.html

patel
11-05-2012, 11:27 AM
thank for better code and very useful link, no way using dos commands ?

snb
11-06-2012, 01:12 AM
You can retrieve filelength & date last saved by omitting /b using:
But in that case you have to filter for non relevant lines.


Sub filelist()
With CreateObject("wscript.shell")
sn = filter(Split(.exec("cmd /c dir D:\test\*.* /s /o-n").stdout.readall, vbCrLf),"/")
End With
cells(2,1).resize(UBound(sn)+1) = WorksheetFunction.Transpose(sn)
End Sub

patel
11-06-2012, 06:19 AM
Thanks again