-
Mar 21st, 2012, 10:36 PM
#1
Directory/File Lister
This is a basic directory and file lister I created about 10 years back. I though I would paste the code here incase others could improve on it.
vb Code:
'You need: '1 Drive List Box called Drive1 '1 Directory List Box called Dir1 '1 File lisrt box called File1 '1 Combo box called cmbType '2 Command Buttons 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!") 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. For n = 1 To File1.ListCount Open App.Path & "\Files.txt" For Append As #1 Print #1, File1.List(n) Close #1 Next n 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!") End Sub Private Sub Form_Load() frmDFL.Caption = "Directory and File Lister" 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
Nightwalker
Last edited by Nightwalker83; Mar 21st, 2012 at 10:43 PM.
Reason: Fixing comments!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 21st, 2012, 09:18 AM
#2
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
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Nov 22nd, 2012, 09:16 PM
#3
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.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
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
|