473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to work efficiently with the filesystemobject?

TheSmileyCoder
2,322 Expert Mod 2GB
I am working on a app in which the start process is to collect information on all files stored within a folder (and its subfolders).

To that purpose I have started the following code, to look through the folder, and its subfolders:
Expand|Select|Wrap|Line Numbers
  1. Public Sub CollectInfo()
  2. On Error GoTo err_Handler
  3.    Dim t As Date
  4.    t = Now()
  5.    Dim fs As New FileSystemObject
  6.    Dim myFolder As Folder
  7.    Set myFolder = fs.GetFolder("G:\TestFiles")
  8.    Dim rsFiles As DAO.Recordset
  9.    Set rsFiles = CurrentDb.OpenRecordset("tbl_Files")
  10.    Dim oFolder As Folder
  11.    Dim oFile As File
  12.    For Each oFolder In myFolder.SubFolders
  13.       For Each oFile In oFolder.Files
  14.  
  15.          Dim s As String
  16.          s = oFile.Name & oFile.Path
  17.          'rsFiles.AddNew
  18.          '   rsFiles!tx_FileName = oFile.Name
  19.          '   rsFiles!tx_FilePath = oFile.Path
  20.          'rsFiles.Update
  21.  
  22.  
  23.  
  24.       Next oFile
  25.    Next oFolder
  26.  
  27.  
  28.    MsgBox "Procedure completed in: " & Second(Now() - t)
  29. exitSub:
  30.    Set fs = Nothing
  31.    Set oFile = Nothing
  32.    Set oFolder = Nothing
  33.    Set myFolder = Nothing
  34.    Exit Sub
  35.  
  36.  
  37. err_Handler:
  38.    MsgBox Err.Number & Err.Description
  39.    Resume exitSub
  40. End Sub
I have commmented out the part where I intend to add the information to a table for further processing, since I wanted to focus on the efficiency of this step.

It takes the current program 41 seconds to collection information on 270 files in roughly 20 subfolders where the main folder is placed on a network drive.

I get the impression that the filesystemobject is calling the fileserver for the information alot of times, and was wondering if there was any way to get the information needed in a batch processing sort of way to speed it up.

Other speedup suggestions are appreciated as well!
May 29 '12 #1
4 2128
Rabbit
12,516 Expert Mod 8TB
Perhaps instead of a using file system object you could use a batch command and parse the output from that?
May 29 '12 #2
TheSmileyCoder
2,322 Expert Mod 2GB
Interesting. I have not worked much with batch files. How would you go about getting the information from the batch file?

Can you have the information directly returned (like a function call) or would I need the batch file to write the information to a file and then read that file?
May 29 '12 #3
Rabbit
12,516 Expert Mod 8TB
I found this: http://pastebin.com/CszKUpNS. It apparently allows you to redirect the output. I haven't tested it though so if you use it, let me know if it works.
May 29 '12 #4
NeoPa
32,556 Expert Mod 16PB
You might also like to try working with the Dir() function. It's a little more basic but could probably work quite efficiently. Take care not to start a new Dir() run before the previous one has completed though, as each subsequent call is a follow-on from the previous call unless reset with new parameters.
Jun 2 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: John Dewbert | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Hello, I have trouble passing a folder object (from a FileSystemObject) to a sub procedure. Consider the following code: ...
9
by: MDW | last post by:
I'm not sure if this is a coding problem or an IIS settings problem. I've enabled IIS on my local machine (Windows XP SP2) so I can do some ASP development prior to rolling out my Web page to a...
9
by: kermit | last post by:
I keep seeing that you can use the FileSystemObject in either VB script, or Javascript on an aspx page. I added a refrence to the scrrun.dll I added importing namespaces for 'System.Object',...
2
by: Luis Esteban Valencia | last post by:
I'm trying to write a little VB.NET script in an ASP.NET web page that will create folders, move files, etc... pretty much everything you can expect to do using the FileSystemObject library. Is...
1
by: G Gerard | last post by:
Hello I am using the FileSystemObject to copy files on a computer Dim MyObject as Object
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
31
by: krypto.wizard | last post by:
How to divide a number by 7 efficiently without using - or / operator. We can use the bit operators. I was thinking about bit shift operator but I don't know the correct answer.
3
by: brigitte | last post by:
The original problem: I need a procedure to import a csv file created by a third party application into an Access database. This file contains fields which may include commas, and when they do,...
12
lee123
by: lee123 | last post by:
why is this so hard to do. i have alot of books that have exaples of how to do these things but when i try the exaples they never work i have a previous post on "copying files" some of the other guys...
1
by: Dave Smith | last post by:
Would someone please help me by checking my rank table in my database? Please let me know if you feel it setup properly and that the formulas work efficiently. Database Attached The one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.