Results 1 to 5 of 5

Thread: CD folder and file count

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    2

    Question CD folder and file count

    I want get count of files and folders exist in CD very fast, Like windows in my computer in propertise of each folder.
    for sample "Cd contain : 25 Folders,120 Files"

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: CD folder and file count

    Code:
    Option Explicit
    
    Private Sub Dir1_Change()
    File1.Path = Dir1.Path
    Text1.Text = File1.ListCount
    End Sub
    
    Private Sub Form_Load()
    On Error Resume Next
    Drive1.Path = "D:"
    End Sub
    All you need is:
    DirListBox called Dir1
    FileListBox called File1
    TextBox called Text1

    and use that code It is simple and not the best way but it does work.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    2

    Re: CD folder and file count

    no.I want count of all subfolders and files

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: CD folder and file count

    Use FileSystemObject.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: CD folder and file count

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim DirsCount As Long, FilesCount As Long
        
        DirList "C:\", DirsCount, FilesCount
        
        MsgBox FilesCount & " Files, " & DirsCount & " Folders"
    End Sub
    
    Private Sub DirList(ByVal Root As String, DirsCount As Long, FilesCount As Long)
        Dim sDir As String
        Dim Dirs As New Collection
        If Right(Root, 1) <> "\" Then Root = Root & "\"
        
        On Error Resume Next
        sDir = Dir(Root & "*", vbArchive + vbDirectory + vbHidden + vbReadOnly + vbSystem)
        
        Do Until Len(sDir) = 0
            If sDir <> "." And sDir <> ".." Then
                If (GetAttr(Root & sDir) And vbDirectory) = vbDirectory Then
                    If Err.Number = 0 Then
                        Dirs.Add sDir
                        DirsCount = DirsCount + 1
                    Else
                        FilesCount = FilesCount + 1
                        Err.Clear
                    End If
                Else
                    FilesCount = FilesCount + 1
                End If
            End If
            
            sDir = Dir
        Loop
        
        Do Until Dirs.Count = 0
            DirList Root & Dirs(1), DirsCount, FilesCount
            Dirs.Remove 1
        Loop
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width