Solved

How to get all the file name in a folder?

Posted on 2002-07-24
6
226 Views
Last Modified: 2012-05-04
Hi Experts,

My question is... how can i get all the file name which located in a specific folder?

For example, there are file1.txt, file2.txt and file3.txt inside MyFolder. But i've no idea at all what files and how many files are inside the folder, what i knew is juz the specific path to the folder name (e.g. C:\MyDocument\MyFolder\)

So base on the limited info i have, can i retrieve all the file names inside that specific folder?

I did try on FileSystemObject's GetFileName function, but this is not wat i want.

So, experts do u have any ideas on it??... plz share with me!

Thanx...

Regards,
Jilim

0
Comment
Question by:jilim
6 Comments
 
LVL 39

Expert Comment

by:appari
ID: 7176091
something like this

dim strFilePath as string
dim strFileName as string

strFilePath="C:\MyDocument\MyFolder\"
strFileName=dir(strFilePath & "*.*")
while strFileName<>""
    debug.print strFileName
    strFileName=dir()
wend

0
 
LVL 2

Expert Comment

by:mmcmillen
ID: 7176188
use a filelistbox and read through each item.  That will also give you the ability to filter for certain file types, or wildcards.
0
 

Author Comment

by:jilim
ID: 7176239
Hi Appari & mmcmillen,

can i use this in VBScript...coz i'll be execute it in .vbs format.

mmcmillen, can u explain more detail or show me the example of filelistbox function?

thanx...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Accepted Solution

by:
TravisHall earned 50 total points
ID: 7176456
In VBScript, you will need to use the FileSystemObject object, a Folder object, and File objects. Something like...


Dim fso
Dim fol
Dim fil

Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder("C:\MyDocument\MyFolder")
For Each fil In fol.Files
    MsgBox fil.Name
Next


That should give you a series of message boxes each telling you the name of one of the files. (Of course, you can do other things with the File object, but that's just an example.)

I would recommend reading about these objects in the VBScript documentation.
0
 

Author Comment

by:jilim
ID: 7176499
Thanx.. Travis!
0
 

Author Comment

by:jilim
ID: 7176500
Thanx Travis!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question