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?
Using the filelist box, i want to get the date of the file selected, is this possible?
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.
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.Fi leSystemOb ject")
dteLastModified = objFSO.GetFile(strFileName ).DateLast Modified
MsgBox strFileName & vbCrLf & "was last modified on: " & dteLastModified
End If
Regards,
Rob.
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.Fi
dteLastModified = objFSO.GetFile(strFileName
MsgBox strFileName & vbCrLf & "was last modified on: " & dteLastModified
End If
Regards,
Rob.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'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.Fi
Set f = fso.GetFolder(folderList(f
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(FolderLi
FolderList(ubound(FolderLi
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.Fi
Set f = fso.GetFolder(FolderList(n
For Each file In f.Files
dslc = DateDiff("d",Now,file.date
dslm = DateDiff("d",Now,file.date
dsla = DateDiff("d",Now,file.date
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