Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get all the file name in a folder?

Posted on 2002-07-24
6
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

670 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