getting the date from a file

Using the filelist box, i want to get the date of the file selected, is this possible?
Who is Participating?
peetmConnect With a Mentor Commented:
Although I'm a huge fan of the Scripting Runtime you can do this in VB itself - which if you haven't used the FSO for anything else, gives you one less dependency to worry about:

    Dim fileName As String
    fileName = File1.Path & File1.fileName

    MsgBox "fileName's date/time is " & FileDateTime(fileName)
'Recursive directory file list
'July 2007 - Robert Heritage -
'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
End If
FolderIndex = FolderIndex + 1

'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

This is something I found.
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.

if cdlg.FileName = "" Then
    ' User canceled.
    ' 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


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.