• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 544
  • Last Modified:

getting the date from a file

Hi,
Using the filelist box, i want to get the date of the file selected, is this possible?
0
markmchugh
Asked:
markmchugh
  • 2
1 Solution
 
geneusCommented:
'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
0
 
geneusCommented:
This is something I found.
0
 
RobSampsonCommented:
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.
0
 
peetmCommented:
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)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now