Dir versus FSO

Posted on 2005-03-11
Medium Priority
Last Modified: 2009-12-16
Hi Everyone,

In regards to using the Dir command and using FileSystemObject, I'm curious as to what people think is better.  I used to use dir for everything, until about a year ago when someone pointed out to me (I can't find the thread) that FSO is more efficient.  I've been using that for everything, until I read PaulHews' comment at http:Q_21347422.html#13519390 .  Since I trust his opinion, it got me to think that I'm not writing as good code as I could be.  Personally I think that FSO is easier to understand, and easier to recurse subdirectories, but that could be because I use it more.

What are people's thoughts on this?

Question by:mvidas
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
  • 3
  • 2
  • 2
  • +2

Assisted Solution

by:Steve Sirica
Steve Sirica earned 500 total points
ID: 13520515
dir has a smaller foot print but I think FSO is more powerfull and flexible.
LVL 23

Accepted Solution

gecko_au2003 earned 500 total points
ID: 13520574
I agree with that but also would suggest looking into the API's with regards to finding files ie FindFirstFile() FindNextFile() API's I think it is something like that :)

Take a look here :


That explains it and compares API Versus FSO and other things :) I hope this helps
LVL 38

Assisted Solution

PaulHews earned 500 total points
ID: 13520789
Time to revive PAFSO
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 38

Expert Comment

ID: 13520819
Dir is useless for recursive searches, but to iterate through files in a single directory, it doesn't make sense to load up the fso.
LVL 35

Author Comment

ID: 13521126
Thanks all, good information so far. I've got a bit of reading to do on it, but from what I read so far looks like I might become a member of pafso :)
LVL 23

Expert Comment

ID: 13522342
how do you become a member of pafso , I click on the links and it comes with an error page saying that it does not exist or something to that extent :) I must be doing something wrong h03h03h03h03

Assisted Solution

cjard earned 500 total points
ID: 13526660
@paulhews; dir is easy to recurse. as you know, it doesnt maintin recursive state so you need to store the paths you wish to investigate in an array, something like this:

public sub recurseDir(path as String)

  If path = "" Then Exit Sub

  Dim dirs as String
  Dim toInvestigate() as String

  Dim file as String
  file = Dir(path, vbNormal)
  While file <> ""
    Debug.Print path & "\" & file

  file = Dir(path, vbDirectory)
  While  file <> ""
    dirs = path & "\" & file & "*"

  toInvestigate = Split(dirs, *)
  Dim i as Integer
  For i = 0 to UBound(toInvestigate)
  Next i
End Sub

the dirs array is separated by *, something not allowed in file names, perhaps better options exist, like Chr(0)
the trailign * on dirs ensures that the last element of toInvestigate is actually a blank string ""
this terminated the recursion
LVL 35

Author Comment

ID: 13591605
Sorry it took so long to get this closed, I've been playing with the APIs, though want to play a bit more before I start using it regularly.

Thanks everyone!  As this was more of an opinion question, I'm splitting the points equally.
LVL 23

Expert Comment

ID: 13591673
Glad we managed to help you out :) and thank you for the grade and points :)

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 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…
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

764 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