
Option Explicit
Private oFileSys As Object, nFiles As Long, nSubDirs As Long, ext_file As String
Sub elenco_files_e_cartelle()
Dim source As String, i As Long, j As Long, v As Variant, ext As Variant, c As Collection
source = "d:car"
Set oFileSys = CreateObject("Scripting.FileSystemObject")
[A:C].Clear
GetDir1 source, i
[c1].Select
MsgBox "Completato"
End Sub
Private Function GetDir1(dir, i As Long) As Long
Dim oFolder As Object, oFolders As Object, oFiles As Object, oFold As Object, oFile As Object
Set oFolder = oFileSys.GetFolder(dir)
Set oFolders = oFolder.SubFolders
On Error GoTo gest_err
For Each oFold In oFolders
i = i + 1
If i > Rows.Count Then MsgBox "Limite del foglio raggiunto!": Exit Function
Cells(i, 2) = oFold.Name
Cells(i, 2).Font.Bold = 1
GetDir1 oFold, i
Next
Exit Function
gest_err:
If Err.Number = 70 Then Resume Next
End Function
Function duplicates(vettore As Variant) As Collection
Dim v As Variant, dups As Collection
Set dups = New Collection
On Error Resume Next
For Each v In vettore
dups.Add CStr(v), v
Next
On Error GoTo 0
Set duplicates = dups
End Function
|
Option Explicit
Private oFileSys As Object
Sub elenco_files_e_cartelle()
Dim source As String, i As Long, j As Long, v As Variant, ext As Variant, c As Collection
source = "C:Documents and Settings5314495DocumentiDocumenti NOPPart. 35 - Riunioni periodiche (già art. 11)"
Set oFileSys = CreateObject("Scripting.FileSystemObject")
[A:Z].Clear
get_dir source, 1, 1
[C1].Select
MsgBox "Completato"
End Sub
Private Function get_dir(dir, ByVal level As Integer, start_row As Long) As Long
Dim oFolder As Object, oSubFolders As Object, oFold As Object
Dim i As Long
Set oFolder = oFileSys.GetFolder(dir)
Set oSubFolders = oFolder.SubFolders
Cells(start_row, level) = oFolder.Name
Cells(start_row, level).Font.Bold = True
start_row = start_row + 1
If start_row > Rows.Count Then MsgBox "Limite del foglio raggiunto!": Exit Function
If oFolder.SubFolders.Count > 0 Then level = level + 1
For Each oFold In oSubFolders
get_dir oFold, level, start_row
Next
Exit Function
End Function |
Option Explicit
Private oFileSys As Object
Sub elenco_files_e_cartelle()
Dim source As String, i As Long, C As Long, j As Long, R As Long, R1 As Long, v As Variant, ext As Variant 'c As Collection
source = "D:CAR"
Sheets("Foglio8").Select
Set oFileSys = CreateObject("Scripting.FileSystemObject")
[B4:ZZ1000].Clear
'[A:Z].Clear
C = 2 'C= COLONNA SOTTOCARTELLE
R = 2 'R=COLONNA CARTELLE PRINCIPALE
GetDir1 source, i, C, R, R1
[a1].Select
MsgBox "Ho terminato."
End Sub
' ********** GETDIR 1 *********
Private Function GetDir1(dir, i As Long, C As Long, R As Long, R1 As Long) As Long
Dim oFolder As Object, oFolders As Object, oFiles As Object, oFold As Object, oFile As Object
Set oFolder = oFileSys.GetFolder(dir)
Set oFolders = oFolder.SubFolders
On Error GoTo gest_err
For Each oFold In oFolders '''''oFold
i = i + 1
If i > Rows.Count Then MsgBox "Limite del foglio raggiunto!": Exit Function
' Cells(i, 2) = oFold.Name ')oFold.Path & " * " & oFold.Name ')
' Cells(i, 2).Font.Bold = 1 ')
'GetDir1 oFold, i, w
Cells(4, R) = oFold.Name ' R=COLONNA CARTELLE PRINCIPALI
R1 = 6 'R1= RIGA DELLE SOTTOCARTELLE
GetDir2 oFold, i + 1, C, R1
C = C + 1
R = R + 1
Next
Exit Function
gest_err:
If Err.Number = 70 Then Resume Next
End Function
' ********** GETDIR 2 *********
Private Function GetDir2(dir, i As Long, C As Long, R1 As Long) As Long
Dim oFolder As Object, oFolders As Object, oFiles As Object, oFold As Object, oFile As Object
Set oFolder = oFileSys.GetFolder(dir)
Set oFolders = oFolder.SubFolders
On Error GoTo gest_err
For Each oFold In oFolders '''''oFold
i = i + 1
If i > Rows.Count Then MsgBox "Limite del foglio raggiunto!": Exit Function
Cells(R1, C) = oFold.Name ')oFold.Path & " * " & oFold.Name ')
Cells(R1, C).Font.Bold = 1 ')
R1 = R1 + 1
'GetDir2 oFold, i
Next
' Next
Exit Function
' ************* GEST ERRORI *********
gest_err:
If Err.Number = 70 Then Resume Next
End Function |
