473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 developers and data experts.

FileSystemObject model - how to list files in a directory (VB6)

8,435 Expert 8TB
Here's a simple VB6 code snippet that uses the FileSystemObject model to find all the files in C:\Temp and load their names into a listbox. To use this sample, you need to set things up as follows:
  • Create a new project in VB6
  • Add a form (this will probably happen by default, anyway)
  • Pull down the Project menu and choose References.
  • Find Microsoft Scripting Runtime and fill in the checkbox to select it. Click OK.
  • Add a ListBox control to the form - name will be List1.
  • Add a command button to the form - name will be Command1.
  • Double-click on the command button to bring up the Click event procedure.
  • Paste in the following code...
    Expand|Select|Wrap|Line Numbers
    1. Dim fso As New FileSystemObject
    2. Dim fld As Folder
    3. Dim fil As File
    4. Set fld = fso.GetFolder("C:\Temp")
    5. For Each fil In fld.Files
    6.   List1.AddItem fil.Name
    7. Next
    8. Set fil = Nothing
    9. Set fld = Nothing
    10. Set fso = Nothing
    Note, some browsers copy the line numbers, so you may need to edit them out before compiling the code.
  • Modify such details as the directory (C:\Temp) if required.
  • Compile and run.
  • Click the command button to fill the listbox with the names of the files in the specified directory.
Aug 23 '07 #1
3 51202
winja
1
Hi, i am learning vbscript. Can you help me with vbscript, or is it only vb? I am a vitial impared person and find it difficult to get a good book on vbscript. I have some more questions, but enough for now. Thank you.
Mar 6 '08 #2
Killer42
8,435 Expert 8TB
Hi, i am learning vbscript ...
We're glad to try and help with VBScript, but we might not always be aware of the exact differences between that and VB. Certainly I'd expect FileSystemObject to work pretty much the same.

Please post any VB or VBScript questions in the Visual Basic forum.
Mar 6 '08 #3
hi, iam learning vb6 now. i want to add all files in a folder to a list by using for..next loop. i dont want to use for each loop. is it possible to do so...please help me
Mar 4 '19 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: J P Singh | last post by:
Hi All I want to create a webpage which will list all the files in particular folder and hyperlink to them to allow users to view the grpahics online without having to send each file to them by...
3
by: Mary Jane Pronio | last post by:
What I want to do is take that output, use the data within it to put into a shell script as input to another installation of DB2 Connect on another AIX box. Any ideas about how to do this?
0
by: Don | last post by:
I intermittently get a runtime Compilation Error that says 'The compiler failed with error code 2000'. It appears that a DLL cannot be found in the 'temporary asp.net files' directory. The...
1
by: Shawn Mehaffie | last post by:
I have an application I want to be able to: 1) Store user specifc settings in ther "My Documents". 2) Store some information in "All Users" document directory. 3) I also want to be able to...
0
by: kumar_ps | last post by:
How to add tif files using vb6.0 I mean suppose if we take 3tif files that all files will add under 1tif file
1
by: dcruncher4 | last post by:
DB2 8.2.3 is there a sql equivalent to get the information provided by db2 list node directory db2 list db directory. thanks.
1
by: mmohanra | last post by:
I am trying to list files in a folder in a remote server. I am using Scripting.FileSystemObject. This seems to be really slow. After a long time the connection times out. Is there any other way to...
3
by: froditus | last post by:
Hello everyone, is it possible to list files from directory other than in apache web directory? my web folder is placed on c:/ and i put my files in windows directory "d:/files/images/". I...
0
by: ravitunk | last post by:
hello all...can anyone tell me how to merge two pdf files using VB6...I have a pdf with plain text and the other pdf with a header and footer....I want to merge these two pdf's....please reply...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.