Dim fso As Object
Dim f As Object
Dim TBfile As String
TBfile = ("C:\fileName.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(TBfile)
Me.Text1 = f.Name
' Or you can use f.Name f.drive f.ParentFolder f.Path f.Size f.DateCreated_
' f.DateLastAccessed f.DateLastModified f.shortname f.ShortPath f.Type
Set f = Nothing
Set fso = Nothing
Sub Test()
FileDetails "C:", "Autoexec.bat"
End Sub
Sub FileDetails(fpath As String, fname As String)
Dim objShell As Object
Dim objFolder As Object
Dim vFile As Variant
Dim i As Integer
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(CStr(fpath))
For Each vFile In objFolder.Items
If vFile = fname Then
For i = 0 To 33
Debug.Print _
i & vbTab & _
objFolder.GetDetailsOf(objFolder.Items, i) & ": " & _
objFolder.GetDetailsOf(vFile, i)
Next
End If
Next
Set objFolder = Nothing
Set objShell = Nothing
End Sub
lagbolt said:Here's code I modified slightly
From here...Code:Sub Test() FileDetails "C:", "Autoexec.bat" End Sub Sub FileDetails(fpath As String, fname As String) Dim objShell As Object Dim objFolder As Object Dim vFile As Variant Dim i As Integer Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(CStr(fpath)) For Each vFile In objFolder.Items If vFile = fname Then For i = 0 To 33 Debug.Print _ i & vbTab & _ objFolder.GetDetailsOf(objFolder.Items, i) & ": " & _ objFolder.GetDetailsOf(vFile, i) Next End If Next Set objFolder = Nothing Set objShell = Nothing End Sub
http://www.microsoft.com/technet/scriptcenter/scripts/storage/files/stfivb32.mspx
...which returns the extended properties of a file.
Sub Test()
FileDetails "C:\temp2\", "export.txt"
End Sub
Sub FileDetails(fpath As String, fname As String)
Dim objShell As Object
Dim objFolder As Object
Dim vFile As Variant
Dim i As Integer
Dim getit
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(CStr(fpath))
For Each vFile In objFolder.Items
getit = _
objFolder.GetDetailsOf(objFolder.Items, 9) & ": " & _
objFolder.GetDetailsOf(vFile, 9)
Next
MsgBox getit
Set objFolder = Nothing
Set objShell = Nothing
End Sub
Function GetFileAuthor(filespec As String) As String
[COLOR="Green"]' Returns the extended file property of a file, in this case the author
' Checks that 'filespec' exists and raises an error if not
' Splits the filename from the path locally[/COLOR]
Dim obj As Object
Dim fso As Object
[COLOR="Green"] 'create scripting object to check for existence and manage file path and name[/COLOR]
Set fso = CreateObject("Scripting.FileSystemObject")
[COLOR="Green"] 'check that filespec exists[/COLOR]
If fso.FileExists(filespec) Then
[COLOR="Green"] 'if so, create shell app[/COLOR]
Set obj = CreateObject("Shell.Application")
[COLOR="Green"] 'reference namespace method of shell application[/COLOR]
With obj.NameSpace(fso.GetParentFolderName(filespec))
[COLOR="Green"] 'return extended file property 9 of file indexed by name[/COLOR]
GetFileAuthor = .GetDetailsOf(.Items.Item(fso.GetFileName(filespec)), 9)
End With
Else
[COLOR="Green"] 'file does not exist, so raise custom error[/COLOR]
Err.Raise 40001, "GetFileAuthor()", "File '" & filespec & "' not found"
End If
End Function
Dim path As String
Dim TBfile As String
Dim fullpath As String
Dim FD As FileDialog
Dim name As String
Dim loc As String
Dim obj As Object
Dim getit
Dim f As Object
Dim i
Set FD = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
With FD
.AllowMultiSelect = False
.Filters.Add "PDF", "*.pdf", 1
.Filters.Add "Word", "*.doc", 1
.Filters.Add "Excel", "*.xls", 1
.Filters.Add "Any", "*.*", 1
.ButtonName = "Get Some!"
.Title = "Find File"
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
name = Dir(vrtSelectedItem, vbSystem)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(name)
'create scripting object to check for existence and manage file path and name
Set fso = CreateObject("Scripting.FileSystemObject")
'check that filespec exists
If fso.FileExists(f.path) Then
'if so, create shell app
Set obj = CreateObject("Shell.Application")
'reference namespace method of shell application
With obj.NameSpace(fso.GetParentFolderName(f.path))
'return extended file property 9 of file indexed by name
For i = 0 To 34
getit = .GetDetailsOf(.Items, i) & ":" & .GetDetailsOf(.Items.Item(fso.GetFileName(f.path)), i)
Me.List2.AddItem Item:=getit
Next
End With
Else
'file does not exist, so raise custom error
Err.Raise 40001, "GetFileAuthor()", "File '" & f.path & "' not found"
End If
Next vrtSelectedItem
Else
End If
End With
Set FD = Nothing
Set f = Nothing
Set fso = Nothing