정확히 무엇이 가장 높은 하위 폴더를 찾고 싶습니까? 이것은 아마도 시작하기에 좋은 장소 일 것입니다. 여기
http://www.learnexcelmacro.com/wp/download/
는 스크립트입니다.
Sub GetFilesInFolder(SourceFolderName As String, Subfolders As Boolean)
'--- For Example:Folder Name= "D:\Folder Name\" and Flag as Yes or No
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.folder, SubFolder As Scripting.folder
Dim FileItem As Scripting.File
'Dim r As Long
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
'--- This is for displaying, whereever you want can be configured
r = 14
For Each FileItem In SourceFolder.Files
Cells(r, 2).Formula = r - 13
Cells(r, 3).Formula = FileItem.Name
Cells(r, 4).Formula = FileItem.Path
Cells(r, 5).Formula = FileItem.Size
Cells(r, 6).Formula = FileItem.Type
Cells(r, 7).Formula = FileItem.DateLastModified
Cells(r, 8).Formula = "=HYPERLINK(""" & FileItem.Path & """,""" & "Click Here to Open" & """)"
r = r + 1 ' next row number
Next FileItem
'--- This is the Function to go each and Every Folder and get the Files. This is a Nested-Function Calling.
If Subfolders = True Then
For Each SubFolder In SourceFolder.Subfolders
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub
마지막으로 위의 링크를 구성하면 '파일 관리자'라는 샘플 파일을 다운로드 할 수 있습니다. '지금 다운로드'를 클릭하여 파일을 가져옵니다. 그게 당신이 원하는대로해야합니다.
Project의 하위 폴더는 32145라고하며, ABD라는 폴더도 있습니다. 가장 높은 숫자를 얻고 싶습니다. 현재 33365로 32020에서이 숫자로 반복 할 수 있습니다. 그러나 현재 나는 모든 폴더를 반복하고 그것이> 32020이고 len (foldername) = 5인지 확인합니다. – skatun