• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 995
  • Last Modified:

Dir versus FSO

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?

Matt
0
mvidas
Asked:
mvidas
  • 3
  • 2
  • 2
  • +2
4 Solutions
 
Steve SiricaSenior Web Application EngineerCommented:
dir has a smaller foot print but I think FSO is more powerfull and flexible.
0
 
gecko_au2003Commented:
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 :

http://vbnet.mvps.org/index.html?code/fileapi/countfiles.htm

That explains it and compares API Versus FSO and other things :) I hope this helps
0
 
PaulHewsCommented:
Time to revive PAFSO
http:Q_11499199.html
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
PaulHewsCommented:
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.
0
 
mvidasAuthor Commented:
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 :)
0
 
gecko_au2003Commented:
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
0
 
cjardCommented:
@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
  Wend

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

  toInvestigate = Split(dirs, *)
  Dim i as Integer
  For i = 0 to UBound(toInvestigate)
    recurseDir(toInvestigate(i))
  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
0
 
mvidasAuthor Commented:
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.
Matt
0
 
gecko_au2003Commented:
Glad we managed to help you out :) and thank you for the grade and points :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now