Solved

How to get all the file name in a folder?

Posted on 2002-07-24
6
227 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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
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 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…

738 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