2017-03-14 2 views
-1

많은 하위 폴더가있는 폴더가 있으며 폴더의 98 %가 반복되는 숫자로 패턴을 기반으로 이름이 지정됩니다.가장 높은 숫자를 가진 하위 폴더 찾기

내가 가장 높은 번호 (하위 폴더의 이름, maxNumber = ??)를 찾으려면 어떻게해야합니까?

numOfRows = maxFolder- 32020 

'loops through each file in the directory and prints their names and path 
'For Each objSubFolder In objFolder.subfolders to slow.... 
for pnr = 32020 to maxFolder 
    DoEvents 

    Call ProgressBar.setMessage("Updating for .." & pnr, ((i + 1)/(numOfRows + 1)) * 100) 
+0

Project의 하위 폴더는 32145라고하며, ABD라는 폴더도 있습니다. 가장 높은 숫자를 얻고 싶습니다. 현재 33365로 32020에서이 숫자로 반복 할 수 있습니다. 그러나 현재 나는 모든 폴더를 반복하고 그것이> 32020이고 len (foldername) = 5인지 확인합니다. – skatun

답변

1

정확히 무엇이 가장 높은 하위 폴더를 찾고 싶습니까? 이것은 아마도 시작하기에 좋은 장소 일 것입니다. 여기

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 

마지막으로 위의 링크를 구성하면 '파일 관리자'라는 샘플 파일을 다운로드 할 수 있습니다. '지금 다운로드'를 클릭하여 파일을 가져옵니다. 그게 당신이 원하는대로해야합니다.

관련 문제