Identifiying Folders and Files in Windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iheartvba
    New Member
    • Apr 2007
    • 171

    Identifiying Folders and Files in Windows

    Hi,
    I would like to know how to search through a directory and populate an MS Access table with:

    A. the names of the folders in that directory
    1. the names of the files in those folders
    i. The size in bytes of each file in the folder

    Much Appreciated
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by iheartvba
    Hi,
    I would like to know how to search through a directory and populate an MS Access table with:

    A. the names of the folders in that directory
    1. the names of the files in those folders
    i. The size in bytes of each file in the folder

    Much Appreciated
    Do you need just the 1st Level Folders under the Main Folder (Sub-Folders), or do you need Sub-Sub-Folders, Sub-Sub-Sub Folders, etc.?

    Comment

    • iheartvba
      New Member
      • Apr 2007
      • 171

      #3
      A. Names of of folders in that directory: These folders will be located in Z:\Clients\ so no subfolders just the names of the folders in this directory.
      B.Names of the Files: I want names of all files that exist under that folder and the sub folders, because there are sub folders in each of these folders.
      C:File Size in Bytes: This is the file size of every File Identified in Point B

      Apologies for the ambiguity

      Thanks,

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by iheartvba
        A. Names of of folders in that directory: These folders will be located in Z:\Clients\ so no subfolders just the names of the folders in this directory.
        B.Names of the Files: I want names of all files that exist under that folder and the sub folders, because there are sub folders in each of these folders.
        C:File Size in Bytes: This is the file size of every File Identified in Point B

        Apologies for the ambiguity

        Thanks,
        1. Set a Reference to the Microsoft Scripting Runtime Library.
        2. For test purposes I created the following Directory structure along with Files contained within each Directory. I posted the layout below:
          1. C:\Clients - (24 Files)
          2. C:\Clients\Fold er 1 - (17 Files)
          3. C:\Clients\Fold er 2 - (14 Files)
          4. C:\Clients\Fold er 3 - (30 Files)
        3. The following code segment will:
          1. List the Clients Directory and any Files container within it along with their sizes.
          2. List Sub-Directories under C:\Clients along with Files in these Directories and their sizes.
        4. I also listed sample OUTPUT from the code.
        5. Posted below is the code segment:
          [CODE=vb]
          Dim fso As FileSystemObjec t
          Dim fldr As Folder
          Dim fldr2 As Folder
          Dim fil1 As File
          Dim fil2 As File

          Set fso = New Scripting.FileS ystemObject

          'Creates an Instance of a Folder
          Set fldr = fso.GetFolder(" C:\Clients")

          Debug.Print fldr.Name
          For Each fil1 In fldr.Files
          Debug.Print " |-- " & fil1.Name & " ==> " & _
          FormatNumber(fi l1.Size, 0) & " bytes"
          Next

          For Each fldr2 In fldr.SubFolders
          Debug.Print " |-- " & fldr2.Name & " (FOLDER)"
          For Each fil2 In fldr2.Files
          Debug.Print " |-- " & fil2.Name & " ==> " & _
          FormatNumber(fi l2.Size, 0) & " bytes"
          Next
          Next[/CODE]

        OUTPUT:
        [CODE=text]
        Clients
        |-- app850.fon ==> 36,672 bytes
        |-- app852.fon ==> 36,656 bytes
        |-- app855.fon ==> 37,296 bytes
        |-- app857.fon ==> 36,672 bytes
        |-- app866.fon ==> 37,472 bytes
        |-- ARBLI___.TTF ==> 65,544 bytes
        |-- arial.ttf ==> 367,112 bytes
        |-- arialbd.ttf ==> 352,224 bytes
        |-- arialbi.ttf ==> 226,748 bytes
        |-- ariali.ttf ==> 207,808 bytes
        |-- ARIALN.TTF ==> 134,188 bytes
        |-- ARIALNB.TTF ==> 139,056 bytes
        |-- ARIALNBI.TTF ==> 138,468 bytes
        |-- ARIALNI.TTF ==> 141,328 bytes
        |-- ARIALUNI.TTF ==> 24,131,012 bytes
        |-- ariblk.ttf ==> 117,028 bytes
        |-- BATANG.TTF ==> 15,519,828 bytes
        |-- BKANT.TTF ==> 155,528 bytes
        |-- BOOKOS.TTF ==> 160,940 bytes
        |-- BOOKOSB.TTF ==> 154,576 bytes
        |-- BOOKOSBI.TTF ==> 162,460 bytes
        |-- BOOKOSI.TTF ==> 160,920 bytes
        |-- CENTURY.TTF ==> 163,828 bytes
        |-- cga40woa.fon ==> 6,336 bytes
        |-- Folder 1 (FOLDER)
        |-- BDEViewerMaster _Test.mdb ==> 4,198,400 bytes
        |-- BDEViewerMaster _Test.zip ==> 753,627 bytes
        |-- CSV.txt ==> 6,511 bytes
        |-- Employees.xls ==> 15,360 bytes
        |-- Inventory.adtg ==> 3,609,432 bytes
        |-- name.txt ==> 14 bytes
        |-- ScreenShot.bmp ==> 2,193,462 bytes
        |-- Some Document.Doc ==> 20,480 bytes
        |-- Some_Document.D oc ==> 20,480 bytes
        |-- Test.bmp ==> 2,193,462 bytes
        |-- Test.doc ==> 20,480 bytes
        |-- Test.mdb ==> 4,272,128 bytes
        |-- Test.txt ==> 0 bytes
        |-- Test2.txt ==> 603,546 bytes
        |-- TestFile3.txt ==> 0 bytes
        |-- TextFile.txt ==> 76 bytes
        |-- TextFile1.txt ==> 0 bytes
        |-- Folder 2 (FOLDER)
        |-- AIRPLANE.JPG ==> 97,922 bytes
        |-- Azul.jpg ==> 61,365 bytes
        |-- BabyGracie14a.J PG ==> 428,327 bytes
        |-- Beach1.jpg ==> 272,945 bytes
        |-- Beach2.jpg ==> 367,058 bytes
        |-- Beach3.jpg ==> 246,440 bytes
        |-- Beach4.jpg ==> 275,061 bytes
        |-- Beach5.jpg ==> 234,769 bytes
        |-- Beach6.jpg ==> 244,807 bytes
        |-- Beach7.jpg ==> 252,238 bytes
        |-- Beach8.jpg ==> 333,326 bytes
        |-- IM000335.JPG ==> 783,918 bytes
        |-- sky1.jpg ==> 101,616 bytes
        |-- sky2.jpg ==> 149,587 bytes
        |-- Thumbs.db ==> 53,248 bytes
        |-- Folder 3 (FOLDER)
        |-- #9291-1.doc ==> 87,552 bytes
        |-- a130trans4.pdf ==> 93,713 bytes
        |-- Access Automation.doc ==> 21,504 bytes
        |-- Access Project.adp ==> 69,120 bytes
        |-- Annual Meeting.doc ==> 19,968 bytes
        |-- Death Benefits.xls ==> 15,360 bytes
        |-- ERRORS.TXT ==> 566 bytes
        |-- Financials.doc ==> 26,624 bytes
        |-- Function FieldTypeName.d oc ==> 25,600 bytes
        |-- Gym Jackets.xls ==> 18,944 bytes
        |-- Help_U_Care.xls ==> 48,128 bytes
        |-- Jackets.doc ==> 20,480 bytes
        |-- Jackie.doc ==> 20,480 bytes
        |-- My Money Backup.mbf ==> 2,360,253 bytes
        |-- My Money.mny ==> 2,359,296 bytes
        |-- Pass Through Query.doc ==> 19,968 bytes
        |-- PNC On Line Banking.doc ==> 23,552 bytes
        |-- Reference 1.xls ==> 14,848 bytes
        |-- Reference 2.xls ==> 15,360 bytes
        |-- Reference 3.xls ==> 14,848 bytes
        |-- Reference 4.xls ==> 15,872 bytes
        |-- Reference 5.xls ==> 16,384 bytes
        |-- Reference 6.xls ==> 16,384 bytes
        |-- rptEmployee.snp ==> 999,979 bytes
        |-- Scripting.mdb ==> 122,880 bytes
        |-- Test.adp ==> 39,424 bytes
        |-- Test.mdb ==> 11,444,224 bytes
        |-- Test.xls ==> 37,888 bytes
        |-- United Savings.doc ==> 23,552 bytes
        |-- Word Form Fields.doc ==> 22,016 bytes[/CODE]

        Comment

        Working...