Public Sub SpanAndLog(DefaultFolderNumber As Integer)
InitializeSpan DefaultFolderNumber
InitializeSummationSpan DefaultFolderNumber
DesmarcarFound
CurrentDb.Execute "qryClearFolders"
CurrentDb.Execute "qryClearSummations"
End Sub
Public Sub InitializeSpan(DefaultFolderNumber As Integer)
Set FSO = New FileSystemObject
SpanFolders GetDefaultFolderPath(DefaultFolderNumber), DefaultFolderNumber
Set FSO = Nothing
End Sub
Public Sub InitializeSummationSpan(DefaultFolderNumber As Integer)
Set FSO = New FileSystemObject
SpanFolderSummations GetDefaultFolderPath(DefaultFolderNumber), DefaultFolderNumber
UpdateTotalCounts
Set FSO = Nothing
End Sub
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'************************************************************************ Span Folders *********************************************************************************
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub SpanFolders(SourceFolderFullName As String, DefaultFolderNumber As Integer, Optional ParentID As Long = 0, Optional ByVal FolderLevel = 0)
' lists information about the files in SourceFolder
' example: ListFilesInFolder "C:\FolderName\", True
'Dim FSO As Object 'Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder 'Scripting.Folder
Dim SubFolder As Scripting.Folder 'Scripting.Folder
Dim FileItem As Scripting.File 'Scripting.File
' Dim ParentID As Long
Set SourceFolder = FSO.GetFolder(SourceFolderFullName)
FolderLevel = FolderLevel + 1
If Nz(DLookup("FolderFileID", "qryFoldersFiles", "FolderFileFullName1='" & Replace(SourceFolder.Path, "'", "") & "'"), 0) = 0 Then
LogFilesFolders DefaultFolderNumber, SourceFolder.Name, SourceFolder.Path, SourceFolder.Type, SourceFolder.Attributes, ParentID, fft_Folder, FolderLevel, True
End If
ParentID = GetFolderID(SourceFolder.Path)
For Each FileItem In SourceFolder.Files
If Nz(DLookup("FolderFileID", "qryFoldersFiles", "FolderFileFullName1='" & Replace(FileItem.Path, "'", "") & "'"), 0) = 0 Then
LogFilesFolders DefaultFolderNumber, FileItem.Name, FileItem.Path, FileItem.Type, FileItem.Attributes, ParentID, fft_File, FolderLevel, True
End If
Next FileItem
For Each SubFolder In SourceFolder.SubFolders
ParentID = GetFolderID(SourceFolder.Path) ' The record has just been added so get PK by name
' LogFilesFolders SubFolder.Name, SubFolder.Path, SubFolder.Type, ParentID, fft_Folder, FolderLevel
SpanFolders SubFolder.Path, DefaultFolderNumber, ParentID, FolderLevel
Next SubFolder
Set FileItem = Nothing
Set SourceFolder = Nothing
End Sub
Private Sub DesmarcarFound()
On Error GoTo err_lbl
Dim Nombre As String
Dim TblFiles As DAO.Recordset
Set TblFiles = CurrentDb.OpenRecordset("tblFoldersFiles")
If TblFiles.EOF Then Exit Sub
With TblFiles
Do Until TblFiles.EOF
.Edit
Select Case !FileType
Case "Carpeta de archivos"
If Dir(!FolderFileFullName, vbDirectory) = "" Then
!Found = False
Else
!Found = True
End If
Case "Oculto"
!Found = False
Case Else
Nombre = !FolderFileFullName
If Dir(!FolderFileFullName, vbArchive) = "" Then
!Found = False
Else
!Found = True
End If
End Select
.Update
.MoveNext
Loop
End With
TblFiles.Close
Set TblFiles = Nothing
err_exit:
Exit Sub
err_lbl:
MsgBox Nombre
Resume Next
End Sub
Private Sub SpanFolderSummations(SourceFolderFullName As String, DefaultFolderNumber As Integer, Optional ParentID As Long = 0, Optional ByVal FolderLevel = 0, Optional CountHiddenSystem As Boolean = False)
' lists information about the files in SourceFolder
' example: ListFilesInFolder "C:\FolderName\", True
'Dim FSO As Object 'Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder 'Scripting.Folder
Dim SubFolder As Scripting.Folder 'Scripting.Folder
Dim FileItem As Scripting.File 'Scripting.File
Dim FolderCount As Long
Dim FileCount As Long
FolderLevel = FolderLevel + 1
Set SourceFolder = FSO.GetFolder(SourceFolderFullName)
If CountHiddenSystem Then
FolderCount = SourceFolder.SubFolders.Count
Else
FolderCount = 0
For Each SubFolder In SourceFolder.SubFolders
'If (SubFolder.Attributes And 2) <> 2 And (SubFolder.Attributes And 4) <> 4 Then
FolderCount = FolderCount + 1
'End If
Next SubFolder
End If
If CountHiddenSystem Then
FileCount = SubFolder.Files.Count 'This will count hidden as well
Else
FileCount = 0
For Each FileItem In SourceFolder.Files
If FileItem.Type <> "Acceso directo" And FileItem.Type <> "Archivo SRT" And FileItem.Type <> "Documento Adobe Acrobat" Then
FileCount = FileCount + 1
End If
Next FileItem
End If
If Nz(DLookup("FolderID", "qryFolderSummations", "FolderFullName1='" & Replace(SourceFolder.Path, "'", "") & "'"), 0) = 0 Then
LogFolderSummations DefaultFolderNumber, SourceFolder.Name, SourceFolder.Path, FolderCount, FileCount, ParentID, FolderLevel, SourceFolder.Attributes, True
End If
For Each SubFolder In SourceFolder.SubFolders
ParentID = GetFolderSummationID(SourceFolder.Path)
'FolderCount = SubFolder.SubFolders.Count
'If (SubFolder.Attributes And 2) <> 2 And (SubFolder.Attributes And 4) <> 4 Then
SpanFolderSummations SubFolder.Path, DefaultFolderNumber, ParentID, FolderLevel
'End If
Next SubFolder
Set FileItem = Nothing
Set SourceFolder = Nothing
End Sub