sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I'm using this to loop through a folder and list all found files;
Ideally I need to find the name of each file without the file extension - is it possible?
Code:
Sub GetFolder()
Range("A:L").ClearContents
Range("A1").Value = "Name"
Range("B1").Value = "ParentFolder"
Range("C1").Value = "Size (KB)"
Range("D1").Value = "DateLastModified"
Range("E1").Value = "DateCreated"
Range("F1").Value = "DateLastAccessed"
Range("G1").Value = "Type"
Range("h1").Value = "ShortName"
Range("A1").Select
Dim strPath As String
strPath = ThisWorkbook.Path
Dim OBJ As Object, Folder As Object, File As Object
Set OBJ = CreateObject("Scripting.FileSystemObject")
Set Folder = OBJ.GetFolder(strPath)
Call ListFiles(Folder)
Dim SubFolder As Object
For Each SubFolder In Folder.SubFolders
Call ListFiles(SubFolder)
Call GetSubFolders(SubFolder)
Next SubFolder
Range("A1").Select
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ListFiles(ByRef Folder As Object)
On Error Resume Next
For Each File In Folder.Files
ActiveCell.Offset(1, 0).Select
ActiveCell = File.Name
ActiveCell.Offset(0, 1) = File.ParentFolder
ActiveCell.Offset(0, 2) = (File.Size / 1024) 'IN KB
ActiveCell.Offset(0, 3) = File.DateLastModified
ActiveCell.Offset(0, 4) = File.DateCreated
ActiveCell.Offset(0, 5) = File.DateLastAccessed
ActiveCell.Offset(0, 6) = File.Type
ActiveCell.Offset(0, 7) = File.ShortName
Next File
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub GetSubFolders(ByRef SubFolder As Object)
Dim FolderItem As Object
For Each FolderItem In SubFolder.SubFolders
Call ListFiles(FolderItem)
Call GetSubFolders(FolderItem)
Next FolderItem
End Sub
Ideally I need to find the name of each file without the file extension - is it possible?