Re: Directory/File Lister
Reorganized a couple of lines:
Code:
'You need:
'1 DriveListBox called Drive1
'1 DirListBox called Dir1
'1 FileListBox called File1
'1 ComboBox called cmbType
'2 CommandButtons
Dim n As Integer
Private Sub CmbType_Click()
On Error GoTo err
File1.Pattern = CmbType.Text
Exit Sub
err:
MsgBox "Please select a file type!", vbExclamation
End Sub
Private Sub Command1_Click()
'Close the program
Unload Me
End Sub
'Directory and File Lister
'Version 1.0
'Author: Nightwalker83
'Website: http://aaronspehr.net/
Private Sub Command2_Click()
'Save list to a text file.
Open App.Path & "\Files.txt" For Append As #1 '<-- Moved out of the loop
For n = 1 To File1.ListCount
Print #1, File1.List(n)
Next n
Close #1
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
On Error GoTo err
Dir1.Path = Drive1.Drive
Exit Sub
err:
MsgBox "Please choose another drive!", vbExclamation
End Sub
Private Sub Form_Load()
Me.Caption = "Directory and File Lister" '<-- Made generic
Command1.Caption = "Exit"
Command2.Caption = "Save"
CmbType.Text = "File Type:"
'Library Files.
CmbType.AddItem "*.dll"
'Word Documents.
CmbType.AddItem "*.doc"
'Executables.
CmbType.AddItem "*.exe"
'Text Files.
CmbType.AddItem "*.txt"
'All Files.
CmbType.AddItem "*.*"
End Sub
Re: Directory/File Lister
Thanks for error checking my code! I haven't checked it for errors since I originally wrote it back in 2002.