|
-
Oct 12th, 2000, 10:38 AM
#1
Thread Starter
Evil Genius
I need to write a program which loops through a cd in my D: drive, then lists all of the files on this.
So you've kept reading? I want to end up with these files ijn a list in Excel, though if it is easier, can someone tell me how to put this list inside a listbox & I can work out how to transfer this.
Thank you everone!!!!!
-
Oct 12th, 2000, 12:08 PM
#2
Frenzied Member
if
If don't have any sub folders on your cd , just put
a Filelist and set is path to "d:\".
-
Oct 12th, 2000, 12:12 PM
#3
Must be your lucky day!
Add a reference to the MICROSOFT SCRIPTING RUNTIME library (SCRRUN.DLL) using the project menu.
put a command button and a listbox on your form, dont re-name them yet. Customise the code below to search the appropriate folder / drive.
It uses recursion to go through every single file and folder in the top-level folder (specified at the botton of the code sample.
Mail me for more explanation.
Code:
Option Explicit
Dim MyFSO As New FileSystemObject
Dim FSOFolder As Folder
Sub RecurseDirs(MyFolder As Folder)
Dim FSOSubFolders As Folders
Dim FSOFiles As Files
Dim FSOFile As File
Dim TempFolder As Folder
Set FSOSubFolders = MyFolder.SubFolders
For Each TempFolder In FSOSubFolders
List1.AddItem "DIR... " & TempFolder.Path
Call RecurseDirs(TempFolder)
Next TempFolder
Set FSOFiles = MyFolder.Files
For Each FSOFile In FSOFiles
List1.AddItem FSOFile.Path
Next FSOFile
End Sub
Private Sub Command1_Click()
List1.Clear
Set FSOFolder = MyFSO.GetFolder("C:\Windows\Desktop")
Call RecurseDirs(FSOFolder)
End Sub
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
|