the code i am using is below- the only issues I'm having and i can't figure it out is these things
1) the code is bringing in deleted files it does put a ~ infront of it which is nice i can filter it out but is there a way to just not show them
2) the file is bringing in i think its hidden files or something- its extensions i never even heard of - i only need the files that are truly files such as one note excel, word etc. some of the files are like .DB which i guess is data base files but its not an actual file i am not sure of what it is
3) nice to have not needed: not sure if possible but is there a way to add additional locations or do they have to be each their individual pull if it does have to be individual pulls I'm okay with that just takes longer -
example if i need to pull everything from examplepath and examplepath2 and examplepath3
thanks,
Sub AllFileFolder()
Dim strPath As String
Dim sht As Worksheet
Dim rng As Range
Dim Path As String
Dim fso As Object
Dim fld As Object
Dim fil As Object
strPath = "C:\Users\User\Documents"
Set sht = ActiveWorkbook.Worksheets.Add
Set rng = sht.Cells(1, 1)
rng.Resize(, 5).Value = Array("FileName", "FileLocation", "Extension", "CreationDate", "LastAccessDate", "LastModficationDate")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strPath)
getFilesFromFolder fld, rng
MsgBox "Done", vbOKOnly + vbInformation, "Done"
End Sub
Private Sub getFilesFromFolder(fld As Object, rng As Range)
Dim subfld As Object
Dim fil As Object
On Error GoTo ErrHandler
For Each fil In fld.Files
DoEvents
Set rng = rng.Offset(1)
With rng
.Cells(, 1).Value = fil.Name
.Cells(, 2).Value = fld.Path
.Cells(, 3).Value = Right(fil.Name, Len(fil.Name) - InStrRev(fil.Name, "."))
.Cells(, 4).Value = fil.DateCreated
.Cells(, 5).Value = fil.DateLastAccessed
.Cells(, 6).Value = fil.DateLastModified
End With
Next fil
For Each subfld In fld.SubFolders
getFilesFromFolder subfld, rng
Next subfld
ErrHandler:
End Sub
1) the code is bringing in deleted files it does put a ~ infront of it which is nice i can filter it out but is there a way to just not show them
2) the file is bringing in i think its hidden files or something- its extensions i never even heard of - i only need the files that are truly files such as one note excel, word etc. some of the files are like .DB which i guess is data base files but its not an actual file i am not sure of what it is
3) nice to have not needed: not sure if possible but is there a way to add additional locations or do they have to be each their individual pull if it does have to be individual pulls I'm okay with that just takes longer -
example if i need to pull everything from examplepath and examplepath2 and examplepath3
thanks,
Sub AllFileFolder()
Dim strPath As String
Dim sht As Worksheet
Dim rng As Range
Dim Path As String
Dim fso As Object
Dim fld As Object
Dim fil As Object
strPath = "C:\Users\User\Documents"
Set sht = ActiveWorkbook.Worksheets.Add
Set rng = sht.Cells(1, 1)
rng.Resize(, 5).Value = Array("FileName", "FileLocation", "Extension", "CreationDate", "LastAccessDate", "LastModficationDate")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strPath)
getFilesFromFolder fld, rng
MsgBox "Done", vbOKOnly + vbInformation, "Done"
End Sub
Private Sub getFilesFromFolder(fld As Object, rng As Range)
Dim subfld As Object
Dim fil As Object
On Error GoTo ErrHandler
For Each fil In fld.Files
DoEvents
Set rng = rng.Offset(1)
With rng
.Cells(, 1).Value = fil.Name
.Cells(, 2).Value = fld.Path
.Cells(, 3).Value = Right(fil.Name, Len(fil.Name) - InStrRev(fil.Name, "."))
.Cells(, 4).Value = fil.DateCreated
.Cells(, 5).Value = fil.DateLastAccessed
.Cells(, 6).Value = fil.DateLastModified
End With
Next fil
For Each subfld In fld.SubFolders
getFilesFromFolder subfld, rng
Next subfld
ErrHandler:
End Sub