Basic Code explanation.
_B) When running in the loop for the item that is a folder with some files in it
Because the folder item has just files in it, we can say that for the loop for the item that is a folder, this is the actual coding that is run
Code:Private Sub ReoccurringFileFolderProps(ByVal Pf As String) Rem 0 Let Reocopy = Reocopy + 1 ' Originally the variableReocopyis zero.It will become 1 on first entering the macro.Every time we leave this macro, this number is reduced by 1 So in simple use it will be 1 or zero indicating that a copy is in use.However, should this macro "Call itself", before its finished , ( the recursion idea ) then the vallue will be 2and so on.So effectively it tells us which copy is running at any time Rem 1 Dim objShell As Shell32.Shell: Set objShell = New Shell32.Shell'https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg Dim objFolder As Shell32.Folder: Set objFolder = objShell.Namespace(Pf)' Rem 2 Dim Fil As Shell32.FolderItem For Each Fil In objFolder.Items ' ======= Main Loop ==================================================| ' Dim Clm As Long: ' Global variable Let Clm = Clm + 1 Dim Rw As Long: Let Rw = 1 Let ActiveCell.Offset(Rw, Clm) = objFolder.GetDetailsOf(Fil, 0)' Name Let ActiveCell.Offset(Rw + 1, Clm) = objFolder.GetDetailsOf(Fil, 1) ' Size Let ActiveCell.Offset(Rw + 2, Clm) = objFolder.GetDetailsOf(Fil, 2) ' Type Let ActiveCell.Offset(Rw + 3, Clm) = Left(objFolder.GetDetailsOf(Fil, 3), InStr(1, objFolder.GetDetailsOf(Fil, 3), " ", vbBinaryCompare)) ' Chang Date Let ActiveCell.Offset(Rw + 4, Clm) = Left(objFolder.GetDetailsOf(Fil, 4), InStr(1, objFolder.GetDetailsOf(Fil, 4), " ", vbBinaryCompare)) ' Made Date ' Let ActiveCell.Offset(Rw + 9, 0) = "Dateiversion": Let ActiveCell.Offset(Rw + 9, 1) = objFolder.GetDetailsOf(Fil, 166) Let ActiveCell.Offset(Rw + 5, Clm) = objFolder.GetDetailsOf(Fil, 166) ' File Version '_________________________________________________________________________________________________ ' 2bHere we may pause the macro, whilst another copy of it is started ' Pause first macro, start a second copy Sub ReoccurringFileFolderProps(Pf & "\" & objFolder.GetDetailsOf(Fil, 0)) = ReoccurringFileFolderProps(That to Sub Folder) Rem 0 Let Reocopy = Reocopy + 1 ' Originally the variableReocopyis zero.It will become 1 on first entering the macro.Every time we leave this macro, this number is reduced by 1 So in simple use it will be 1 or zero indicating that a copy is in use.However, should this macro "Call itself", before its finished , ( the recursion idea ) then the vallue will be 2and so on.So effectively it tells us which copy is running at any time Rem 1 Dim objShell As Shell32.Shell: Set objShell = New Shell32.Shell'https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg Dim objFolder As Shell32.Folder: Set objFolder = objShell.Namespace(Pf)' Rem 2 Dim Fil As Shell32.FolderItem For Each Fil In objFolder.Items ' ======= Main Loop ==================================================| ' Dim Clm As Long: ' Global variable Let Clm = Clm + 1 Dim Rw As Long: Let Rw = 1 Let ActiveCell.Offset(Rw, Clm) = objFolder.GetDetailsOf(Fil, 0)' Name Let ActiveCell.Offset(Rw + 1, Clm) = objFolder.GetDetailsOf(Fil, 1) ' Size Let ActiveCell.Offset(Rw + 2, Clm) = objFolder.GetDetailsOf(Fil, 2) ' Type Let ActiveCell.Offset(Rw + 3, Clm) = Left(objFolder.GetDetailsOf(Fil, 3), InStr(1, objFolder.GetDetailsOf(Fil, 3), " ", vbBinaryCompare)) ' Chang Date Let ActiveCell.Offset(Rw + 4, Clm) = Left(objFolder.GetDetailsOf(Fil, 4), InStr(1, objFolder.GetDetailsOf(Fil, 4), " ", vbBinaryCompare)) ' Made Date ' Let ActiveCell.Offset(Rw + 9, 0) = "Dateiversion": Let ActiveCell.Offset(Rw + 9, 1) = objFolder.GetDetailsOf(Fil, 166) Let ActiveCell.Offset(Rw + 5, Clm) = objFolder.GetDetailsOf(Fil, 166) ' File Version '_________________________________________________________________________________________________ ' 2bHere we may pause the macro, whilst another copy of it is started 'If objFolder.GetDetailsOf(Fil, 2) = "Dateiordner" Then Call ReoccurringFileFolderProps(Pf & "\" & objFolder.GetDetailsOf(Fil, 0)) '_________________________________________________________________________________________________ ' If we did pause whilst the above code line set off another copy, then when that is finished we will come here and resume the paused previous copy Next Fil ' ============================== Main Loop=================================================| Let Reocopy = Reocopy - 1' We are finished at this point with this running copy of the macro.This code line will reduce the value indicating the copy number is running since this copy ends in the next line End Sub '_________________________________________________________________________________________________ ' If we did pause whilst the above code line set off another copy, then when that is finished we will come here and resume the paused previous copy ' Stop second macro, resume first macro ' Next Fil ' ============================== Main Loop=================================================| Let Reocopy = Reocopy - 1' We are finished at this point with this running copy of the macro.This code line will reduce the value indicating the copy number is running since this copy ends in the next line End Sub
Private Sub ReoccurringFileFolderProps(ByVal Pf As String)
Rem 0
Let Reocopy = Reocopy + 1 ' Originally the variableReocopyis zero.It will become 1 on first entering the macro.Every time we leave this macro, this number is reduced by 1 So in simple use it will be 1 or zero indicating that a copy is in use.However, should this macro "Call itself", before its finished , ( the recursion idea ) then the vallue will be 2and so on.So effectively it tells us which copy is running at any time
Rem 1
Dim objShell As Shell32.Shell: Set objShell = New Shell32.Shell'https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg https://i.postimg.cc/sDC9S54h/Tools-...Automation.jpg
Dim objFolder As Shell32.Folder: Set objFolder = objShell.Namespace(Pf)'
Rem 2
Dim Fil As Shell32.FolderItem
For Each Fil In objFolder.Items ' ======= Main Loop ================================================== |
' Dim Clm As Long: ' Global variable
Let Clm = Clm + 1
Dim Rw As Long: Let Rw = 1
Let ActiveCell.Offset(Rw, Clm) = objFolder.GetDetailsOf(Fil, 0)' Name
Let ActiveCell.Offset(Rw + 1, Clm) = objFolder.GetDetailsOf(Fil, 1) ' Size
Let ActiveCell.Offset(Rw + 2, Clm) = objFolder.GetDetailsOf(Fil, 2) ' Type
Let ActiveCell.Offset(Rw + 3, Clm) = Left(objFolder.GetDetailsOf(Fil, 3), InStr(1, objFolder.GetDetailsOf(Fil, 3), " ", vbBinaryCompare)) ' Chang Date
Let ActiveCell.Offset(Rw + 4, Clm) = Left(objFolder.GetDetailsOf(Fil, 4), InStr(1, objFolder.GetDetailsOf(Fil, 4), " ", vbBinaryCompare)) ' Made Date
' Let ActiveCell.Offset(Rw + 9, 0) = "Dateiversion": Let ActiveCell.Offset(Rw + 9, 1) = objFolder.GetDetailsOf(Fil, 166)
Let ActiveCell.Offset(Rw + 5, Clm) = objFolder.GetDetailsOf(Fil, 166) ' File Version
'_________________________________________________ ________________________________________________
' 2bHere we may pause the macro, whilst another copy of it is started
' Pause first macro, start a second copy
Sub ReoccurringFileFolderProps(Pf & "" & objFolder.GetDetailsOf(Fil, 0)) = ReoccurringFileFolderProps(That to Sub Folder)
Rem 0
Let Reocopy = Reocopy + 1 ' Originally the variableReocopyis zero.It will become 1 on first entering the macro.Every time we leave this macro, this number is reduced by 1 So in simple use it will be 1 or zero indicating that a copy is in use.However, should this macro "Call itself", before its finished , ( the recursion idea ) then the vallue will be 2and so on.So effectively it tells us which copy is running at any time
Rem 1
Dim objShell As Shell32.Shell: Set objShell = New Shell32.Shell'https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg https://i.postimg.cc/sDC9S54h/Tools-...Automation.jpg
Dim objFolder As Shell32.Folder: Set objFolder = objShell.Namespace(Pf)'
Rem 2
Dim Fil As Shell32.FolderItem
For Each Fil In objFolder.Items ' ======= Main Loop ================================================== |
' Dim Clm As Long: ' Global variable
Let Clm = Clm + 1
Dim Rw As Long: Let Rw = 1
Let ActiveCell.Offset(Rw, Clm) = objFolder.GetDetailsOf(Fil, 0)' Name
Let ActiveCell.Offset(Rw + 1, Clm) = objFolder.GetDetailsOf(Fil, 1) ' Size
Let ActiveCell.Offset(Rw + 2, Clm) = objFolder.GetDetailsOf(Fil, 2) ' Type
Let ActiveCell.Offset(Rw + 3, Clm) = Left(objFolder.GetDetailsOf(Fil, 3), InStr(1, objFolder.GetDetailsOf(Fil, 3), " ", vbBinaryCompare)) ' Chang Date
Let ActiveCell.Offset(Rw + 4, Clm) = Left(objFolder.GetDetailsOf(Fil, 4), InStr(1, objFolder.GetDetailsOf(Fil, 4), " ", vbBinaryCompare)) ' Made Date
' Let ActiveCell.Offset(Rw + 9, 0) = "Dateiversion": Let ActiveCell.Offset(Rw + 9, 1) = objFolder.GetDetailsOf(Fil, 166)
Let ActiveCell.Offset(Rw + 5, Clm) = objFolder.GetDetailsOf(Fil, 166) ' File Version
'_________________________________________________ ________________________________________________
' 2bHere we may pause the macro, whilst another copy of it is started
'If objFolder.GetDetailsOf(Fil, 2) = "Dateiordner" Then Call ReoccurringFileFolderProps(Pf & "" & objFolder.GetDetailsOf(Fil, 0))
'_________________________________________________ ________________________________________________
' If we did pause whilst the above code line set off another copy, then when that is finished we will come here and resume the paused previous copy
Next Fil ' ============================== Main Loop============================================== ===|
Let Reocopy = Reocopy - 1' We are finished at this point with this running copy of the macro.This code line will reduce the value indicating the copy number is running since this copy ends in the next line
End Sub
'_________________________________________________ ________________________________________________
' If we did pause whilst the above code line set off another copy, then when that is finished we will come here and resume the paused previous copy
' Stop second macro, resume first macro
'
Next Fil ' ============================== Main Loop============================================== ===|
Let Reocopy = Reocopy - 1' We are finished at this point with this running copy of the macro.This code line will reduce the value indicating the copy number is running since this copy ends in the next line
End Sub
So what was happening there was
First macro starts
For Each ' First Macro Main Loop =====|
First macro pauses if current item is a sub folder
__Second macro starts to look at files in sub folder
__For Each ' Second Macro Main Loop ===|
__Next' Second Macro Main Loop ===|
__Second macro Ends
First macro resumes
Next ' First Macro Main Loop =====|
First macro ends
Lets put that in words, with an example. Let’s say the Main Folder has 3 items
A file
A sub Folder with 4 files in it
A file
The first macro starts.
Loop 1 starts and analyses the first file properties. First loop ends
Loop 2 starts and analyses the Folder properties, then the first macro pauses
__The second macro starts
__Loop 1 analyses the first file in the sub folder. Loop 1 ends
__Loop 2 analyses the second file in the sub folder. Loop 2 ends
__Loop 3 analyses the third file in the sub folder. Loop 3 ends
__Loop 4 analyses the final file in the sub folder. Loop 4 ends
__The second macro ends
The first macro resumes, Loop 2 ends
, and it loops a third time and analyses the third item from main folder, then it ends
The actual coding run will get longer and longer, either
_ If there are increasing numbers of sub folders at any level – in this case a copy code will be used again and again, - This sort of thing
1
__ Copy 2
1
__ Copy 2
1
, and/ or
_ If a sub folder contains itself sub folders – in this case more and more copies are made and affectively pasted in the middle, - This sort of thing
1
__ Copy 2
____ Copy 3
__ Copy 2
1




Reply With Quote
Bookmarks