Link to home
Start Free TrialLog in
Avatar of markmchugh
markmchugh

asked on

getting the date from a file

Hi,
Using the filelist box, i want to get the date of the file selected, is this possible?
Avatar of geneus
geneus
Flag of United States of America image

'Recursive directory file list
'July 2007 - Robert Heritage - mrheritage@gmail.com
'Please mention me in your script if you use this code :)
' to pipe the output into the file use: cscript thisfile.vbs > outfile.csv


Dlm = ","' Variable Delimiter for output
redim FolderList(0)'A flat list of the directory subtree

FolderList(0) = "c:\"'can also use \\servername\c$ etc but it is sloooow


'This part of the script walks the directory structure and stores all of he folder paths in the FolderList Array.

FolderIndex = 0
Do Until FolderIndex > Ubound(FolderList)

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderList(folderindex))

If f.subfolders.count > 0 Then

For Each folder In f.subFolders

if folder.attributes <> 22 Then 'Exclude hidden system folders
redim preserve FolderList(Ubound(FolderList)+1)
FolderList(ubound(FolderList)) = folder.path
End If
Next
End If
FolderIndex = FolderIndex + 1
Loop


'Set up a header for the output

wscript.echo ubound(FolderList) & " Folders. Root: " &Folderlist(0)
wscript.echo "FileName" & dlm & "Folder" & dlm & "Size" & dlm & "Date Created" & dlm & "Age" & dlm & "Date Modified" & dlm & "UnModified Age" & dlm & "Last Accessed" & dlm & "Unread Age" & dlm & "peers"


'This part of the script Works through the list of folders and outputs the data for each file

for n = 0 to ubound(FolderList)

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(FolderList(n))
For Each file In f.Files
dslc = DateDiff("d",Now,file.datecreated) * -1
dslm = DateDiff("d",Now,file.dateLastModified) * -1
dsla = DateDiff("d",Now,file.dateLastAccessed) * -1

wscript.echo file.Name & dlm & file.parentfolder & dlm & file.size & dlm & file.DateCreated & dlm & dslc & dlm & file.DateLastModified & dlm & dslm & dlm & file.DateLAstAccessed & dlm & dsla & dlm & f.Files.count
Next

next
This is something I found.
Avatar of RobSampson
Hi, you can do this using the Microsoft Scripting Runtime Library, which you'll need to add a reference to in your project properties, then you can use the FileSystemObject.

cdlg.ShowOpen
if cdlg.FileName = "" Then
    ' User canceled.
Else
    ' The FileName property contains the selected file name.
   strFileName = cdlg.FileName
   ' This is the part that uses the Microsoft Scripting Runtime Library (VBScript code)
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   dteLastModified = objFSO.GetFile(strFileName).DateLastModified
   MsgBox strFileName & vbCrLf & "was last modified on: " & dteLastModified
End If

Regards,

Rob.
ASKER CERTIFIED SOLUTION
Avatar of peetm
peetm
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial