Results 1 to 8 of 8

Thread: [RESOLVED] Index All Files On Drive

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Resolved [RESOLVED] Index All Files On Drive

    Is there a simple and fast way to print the paths of all the files on a drive?
    I need to print this list into a text file.

    I know that it can be done using a objects like a Dir listbox etc but I heard that there are faster ways of doing it.
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Index All Files On Drive

    still will take a bit:

    VB Code:
    1. Public Function recursefolderlist(foldername As String) As Boolean
    2.    
    3.     On Error Resume Next
    4.     Dim fso, f, fc, fj, f1
    5.    
    6.     Set fso = CreateObject("scripting.filesystemobject")
    7.    
    8.     If Err.Number > 0 Then
    9.         recursefolderlist = False
    10.         Exit Function
    11.     End If
    12.    
    13.     On Error GoTo 0
    14.     If fso.folderexists(foldername) Then
    15.        
    16.         Set f = fso.getfolder(foldername)
    17.         Set fc = f.subfolders
    18.         Set fj = f.Files
    19.         'for each subfolder in the folder
    20.         For Each f1 In fc
    21.             'do something with the folder name
    22.             Print #1, f1
    23.             'then recurse this function with the sub-folder to get any'
    24.             ' sub-folders
    25.             recursefolderlist (f1)
    26.         Next
    27.        
    28.         'for each folder check for any files
    29.         For Each f1 In fj
    30.             Print #1, f1
    31.         Next
    32.        
    33.         Set f = Nothing
    34.         Set fc = Nothing
    35.         Set fj = Nothing
    36.         Set f1 = Nothing
    37.        
    38.     Else
    39.         recursefolderlist = False
    40.     End If
    41.    
    42.     Set fso = Nothing
    43.    
    44. End Function
    45.  
    46. Private Sub Form_Load()
    47. Me.Show
    48. Open "C:\FILES.txt" For Output As #1
    49.     recursefolderlist "C:\"
    50. Close #1
    51. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526

    Re: Index All Files On Drive

    I had this for writing names of files in a folder and the dates they were modified to a text file; perhaps you can modify if to suit your needs.

    To use this, you'll need a reference in your project to Microsoft Scripting Runtime.

    VB Code:
    1. Private Sub Dir1_Change()
    2.     File1.Path = Dir1.List(Dir1.ListIndex)
    3. End Sub
    4.  
    5. Private Sub Drive1_Change()
    6.     Dir1.Path = Drive1.Drive
    7.     File1.Path = Dir1.List(Dir1.ListIndex)
    8. End Sub
    9.  
    10. Private Sub Command1_Click()
    11.     Dim fso As FileSystemObject
    12.     Dim objFolder As Folder
    13.     Dim objFiles As Files
    14.     Dim objFile As File
    15.    
    16.     Set fso = New FileSystemObject
    17.     Set objFolder = fso.GetFolder(Dir1.List(Dir1.ListIndex))
    18.     Set objFiles = objFolder.Files
    19.    
    20.     ' Open a file to write file names and dates to
    21.     Open "H:\" & Text1.Text For Output As #1
    22.    
    23.     ' Print each file name and date modified to file listing
    24.     For Each objFile In objFiles
    25.         Print #1, objFile.Name, vbTab; objFile.DateLastModified
    26.     Next
    27.     Close #1
    28.     MsgBox "All done !"
    29.    
    30. End Sub
    Attached Images Attached Images  
    Last edited by doofusboy; Apr 19th, 2006 at 11:30 AM.
    Do canibals not eat clowns because they taste funny?

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Index All Files On Drive

    @static, thanks that looks great. I'll try it out right now.

    @doofusboy, looks good but I don't want to use a control for this.
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Index All Files On Drive

    Also, you could have a look here. I know its in Excel, but the code may help.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  6. #6
    Junior Member
    Join Date
    Apr 2006
    Location
    Vancouver, WA
    Posts
    31

    Re: Index All Files On Drive

    Simple, use a batch file! Write the following into notepad, save it to your C drive or the root file of any drive you want to index. Rename from .txt to .bat and then double click on it.

    dir /B /O:N /S > directory_listing.csv

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Index All Files On Drive

    ok Static's code worked perfectly for me!
    Now I just need to find a way to compress a 16MB file to something under 1MB...
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  8. #8
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Index All Files On Drive

    Quote Originally Posted by shirazamod
    ok Static's code worked perfectly for me!
    Now I just need to find a way to compress a 16MB file to something under 1MB...
    I don't even think WinZip would do that.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

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