Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting creation date of all my files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0

I need to make something that will give me all the create dates for word documents in my directory.

Is the script below going to do that for me and if not please advise how I could do this??

Here is what I found but keep getting error message with FILETIME part.
[tt]
Dim hFile As Long ' handle to the opened file
Dim ctime As FILETIME ' receives time of creation
Dim atime As FILETIME ' receives time of last access
Dim mtime As FILETIME ' receives time of last modification
Dim thetime As SYSTEMTIME ' used to manipulate the time
Dim retval As Long ' return value

' First, open the file C:\Mydir\ for read-level access. Note the
' expression necessary to pass 0 as lpSecurityAttributes.
hFile = CreateFile("C:\Mydir", GENERIC_READ, FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
If hFile = -1 Then
Debug.Print "Could not open the file successfully -- aborting."
End ' terminate the program
End If

' Next, get the creation, last-access, and last-modification times.
retval = GetFileTime(hFile, ctime, atime, mtime)
' Convert the creation time to the local time zone.
retval = FileTimeToLocalFileTime(ctime, ctime)
' Convert the FILETIME format to the SYSTEMTIME format.
retval = FileTimeToSystemTime(ctime, thetime)

' Display the date of creation of the file to the user.
Debug.Print "The file was created on "; thetime.wMonth; "-"; thetime.wDay; "-"; thetime.wYear

' Close the file to free up resources.
retval = CloseHandle(hFile)[/tt]
 
try this

Code:
Dim oFSO As Object, oFolder As Object, oFile As Object
Dim sPath As String

sPath = "C:\My Documents\"

Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(sPath) Then
  Set oFolder = oFSO.GetFolder(sPath)
  For Each oFile In oFolder.Files
    If LCase$(Right$(oFile.Name, 4)) = ".doc" Then
      Debug.Print oFile.Name, oFile.DateCreated
    End If
  Next oFile
  
  Set oFolder = Nothing
Else
  MsgBox "Cannot find " & sPath
End If
Set oFSO = Nothing
 
Thanks it works great. I was wondering how I would get your script to work where it asks for input of a folder or specific file and after entering the info it outputs the creation date?
 
That would be easy - just have the sPath variable get changed based on the user input. Then do a check - if it has a .??? at then end, it's a file and you just check it - otherwise you would just treat it as a directory and add a "\" character onto the end if needed. Greg W
wolgemga@aecl.ca
 
Is this the right direction? Sorry I am new to visual basic.

[tt]

Dim oFSO As Object, oFolder As Object, oFile As Object
Dim sPath As String

sPath = $inputvariable

Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(sPath) Then
Set oFolder = oFSO.GetFolder(sPath)
For Each oFile In oFolder.Files
If LCase$(Right$(oFile.Name, 4)) = ".doc" Then
Debug.Print oFile.Name, oFile.DateCreated
End If
Next oFile

Set oFolder = Nothing
Else
MsgBox "Cannot find " & sPath
End If
Set oFSO = Nothing[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top