Solved

How to get all the file name in a folder?

Posted on 2002-07-24
6
221 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now