Apr 19th, 2006, 10:32 AM
#1
Thread Starter
Fanatic Member
[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.
Apr 19th, 2006, 10:48 AM
#2
Re: Index All Files On Drive
still will take a bit:
VB Code:
Public Function recursefolderlist(foldername As String) As Boolean
On Error Resume Next
Dim fso, f, fc, fj, f1
Set fso = CreateObject("scripting.filesystemobject")
If Err.Number > 0 Then
recursefolderlist = False
Exit Function
End If
On Error GoTo 0
If fso.folderexists(foldername) Then
Set f = fso.getfolder(foldername)
Set fc = f.subfolders
Set fj = f.Files
'for each subfolder in the folder
For Each f1 In fc
'do something with the folder name
Print #1, f1
'then recurse this function with the sub-folder to get any'
' sub-folders
recursefolderlist (f1)
Next
'for each folder check for any files
For Each f1 In fj
Print #1, f1
Next
Set f = Nothing
Set fc = Nothing
Set fj = Nothing
Set f1 = Nothing
Else
recursefolderlist = False
End If
Set fso = Nothing
End Function
Private Sub Form_Load()
Me.Show
Open "C:\FILES.txt" For Output As #1
recursefolderlist "C:\"
Close #1
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Apr 19th, 2006, 11:27 AM
#3
Fanatic Member
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:
Private Sub Dir1_Change()
File1.Path = Dir1.List(Dir1.ListIndex)
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
File1.Path = Dir1.List(Dir1.ListIndex)
End Sub
Private Sub Command1_Click()
Dim fso As FileSystemObject
Dim objFolder As Folder
Dim objFiles As Files
Dim objFile As File
Set fso = New FileSystemObject
Set objFolder = fso.GetFolder(Dir1.List(Dir1.ListIndex))
Set objFiles = objFolder.Files
' Open a file to write file names and dates to
Open "H:\" & Text1.Text For Output As #1
' Print each file name and date modified to file listing
For Each objFile In objFiles
Print #1, objFile.Name, vbTab; objFile.DateLastModified
Next
Close #1
MsgBox "All done !"
End Sub
Attached Images
Last edited by doofusboy; Apr 19th, 2006 at 11:30 AM .
Do canibals not eat clowns because they taste funny?
Apr 19th, 2006, 11:39 AM
#4
Thread Starter
Fanatic Member
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.
Apr 19th, 2006, 12:22 PM
#5
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
Apr 19th, 2006, 01:15 PM
#6
Junior Member
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
Apr 21st, 2006, 10:18 AM
#7
Thread Starter
Fanatic Member
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...
Apr 21st, 2006, 10:20 AM
#8
Frenzied Member
Re: Index All Files On Drive
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
Forum Rules
Click Here to Expand Forum to Full Width