Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get all the file name in a folder?

Posted on 2002-07-24
6
Medium Priority
?
235 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
TravisHall earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

824 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