VB6 FileSystemObject makes it easier to work with files
Takeaway: VB6 applications often need to locate logs or other files. The FileSystemObject component gives you a simplified way to implement this functionality in your apps.
In VB6, you often need to implement file search facilities in your applications. For instance, you might need to search for a particular log file on the client machine, get a listing of all files available in the particular directory, or verify that a particular directory or file exists. The simplest way to achieve this is to employ the FileSystemObject component, which provides a useful set of features that can simplify coding.
FileSystemObject component
The FileSystemObject gives you access to the file system. It allows creating, manipulating, deleting, and obtaining information about drives, folders, and files. To use FileSystemObject in your VB code, you need to declare it in the following way:
Dim fso As New FileSystemObject
You can then use its properties and methods, which are shown in Table A.
Table A
|
Table B outlines the most often used methods of the FileSystemObject.
Table B
|
Code example
Let’s take a look at the code that will allow you to go through files in a specified directory and list them in a Listbox control. We'll assume that you have a Listbox control on a form called lstFiles and a C:\Files directory on your system that contains a number of files. Listing A shows the code to retrieve a list of those files.
FileSystemObject limitations
When you implement FileSystemObject, you should keep in mind these limitations:
- · FileSystemObject allows creating ASCII or Unicode text files.
- · FileSystemObject can read only ASCII text files.
- · When reading files, FileSystemObject can read in only one direction and only line by line.
- · A file can’t be open for reading and writing. You can open a file in ForReading mode using OpenTextFile, but to make changes to the file, you would need to open a TextStream object.
- · When searching for files, you can’t use wildcards; you must specify the exact name.
- · When retrieving filenames from the files collection, filenames can’t be sorted. To return them in a specific order, you must add a subroutine to do it.
Conclusion
In this article, we demonstrated a simple way to implement a file search, copy, move, and delete files and folders, and other useful features using FileSystemObject. Next time, we will look at other code examples that will simplify your code.
Print/View all Posts Comments on this article
|
|
|
|
|
|
|
|
|
|
White Papers, Webcasts, and Downloads
- Migration From Oracle 9i on Red Hat 2.1 Advanced Server to Oracle 9i on Red Hat Enterprise Linux (RHEL) 3.0 Dell The purpose of this paper is to provide a procedure for migrating a system ... Download Now
- Secure Copy Version 5.0.2 ScriptLogic Secure Copy? is a powerful, comprehensive migration solution that ... Download Now
- Email Security and Archiving - Clearer in the Cloud Google The time is NOW for businesses and organizations of all sizes to implement ... Download Now
- Dell on OpenManage Dell Dell Computer Corporation runs its business on thousands of Dell PowerEdge ... Download Now
- Memory Analysis Best Practices Within Eclipse Quest Software Poor Java performance costs your business money and customers. However ... Download Now
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET

