-
Please only quote parts of posts if you need to point out some part. Otherwise just say something like, "in Kenneth's post #13, the file with the Duration values are PNG files typically though c:\windows\clock.avi has a duration value for those with Windows XP-".
There are 42 property details that you can get. I could post a routine that can put all into an array but if you only need a few, it should be easy to see how that is done by my code. Notice that you can put the name or word of the property detail and/or the value as well.
Obviously, when testing code, try to test in a blank sheet or even better yet, a blank workbook. Notice that I deleted the contents of the activesheet and put the saved workbook's path into cell C7.
Don't forget to set the two references.
[vba]Sub FileDetails()
ActiveSheet.UsedRange.Clear
Range("C7").Value2 = ThisWorkbook.Path
ListMyFiles Range("C7").Value2, 11
ActiveSheet.UsedRange.Columns.AutoFit
End Sub
' Tools > References > Microsoft Scripting Runtime
' Tools > References > Microsoft Shell Controls and Automation
Sub ListMyFiles(mySourcePath As String, iRow As Long, _
Optional IncludeSubfolders As Boolean = True)
Dim myObject As Scripting.FileSystemObject
Dim mySource As Scripting.Folder
Dim myFile As Scripting.File
Dim mySubFolder As Scripting.Folder
Dim iCol As Integer
Dim wShell As Shell
Set wShell = New Shell
Set myObject = New Scripting.FileSystemObject
Set mySource = myObject.GetFolder(mySourcePath)
On Error Resume Next
For Each myFile In mySource.Files
iCol = 2
Cells(iRow, iCol).Value2 = myFile.Path
iCol = iCol + 1
Cells(iRow, iCol).Value2 = myFile.Name
iCol = iCol + 1
Cells(iRow, iCol).Value2 = myFile.Size
iCol = iCol + 1
Cells(iRow, iCol).Value2 = myFile.DateLastModified
Cells(iRow, iCol).NumberFormat = "mm/dd/yyyy"
iCol = iCol + 1
With wShell.Namespace(mySource.Path)
Cells(iRow, iCol).Value2 = .GetDetailsOf(myFile.Name, 21) 'Duration word.
iCol = iCol + 1
Cells(iRow, iCol).Value2 = .GetDetailsOf(.ParseName(myFile.Name), 21) 'Duration value.
End With
'Range("A" & iRow).Hyperlinks.Add Range("A" & iRow), myFile.Path , , , myFile.Name
Range("A" & iRow).Hyperlinks.Add Range("A" & iRow), myFile.Path , , , myObject.GetBaseName(myFile.Name)
iRow = iRow + 1
Next
If IncludeSubfolders Then
For Each mySubFolder In mySource.SubFolders
ListMyFiles mySubFolder.Path, iRow, True
Next
End If
End Sub
[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules