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.
Printable View
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.
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
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
@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.
Also, you could have a look here. I know its in Excel, but the code may help.
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
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.Quote:
Originally Posted by shirazamod