473,387 Members | 1,535 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,387 software developers and data experts.

File count within folder(s)

i searched these forums for a file counting snippet of code to count the number of files in folder and return a value but i couldn't find one that worked. i just want to have it search the folder under the default folder( meaning the folder under where the .exe file is)

any ideas?
Jun 7 '07 #1
4 13298
Dököll
2,364 Expert 2GB
i searched these forums for a file counting snippet of code to count the number of files in folder and return a value but i couldn't find one that worked. i just want to have it search the folder under the default folder( meaning the folder under where the .exe file is)

any ideas?
Hiya, thumper5!

Here's something that should get you started:

Expand|Select|Wrap|Line Numbers
  1. Public Function FileCount(PathName As String) As Long
  2.   Dim FSO As New FileSystemObject
  3.   Dim fld As Folder
  4.   If FSO.FolderExists(PathName) Then
  5.      Set fld = FSO.GetFolder(PathName)
  6.      FileCount = fld.Files.Count
  7.   End If
  8. End Function
  9.  
Please write if you're stuck. By the way I edited you title to ensure ease of search, especially if someone else is looking.

In a bit!
Jun 8 '07 #2
i found this snippet of code on some site:
Expand|Select|Wrap|Line Numbers
  1.    Private Function GetFileCount(ByVal path As String) As Integer
  2.         'this function will figure out the 
  3.  
  4.         Dim FileCounter As Integer
  5.         path = Dir("../")
  6.         Do While Len(path)
  7.             FileCounter = FileCounter + 1
  8.             path = Dir()
  9.         Loop
  10.  
  11.         Return FileCounter
  12.  
  13.     End Function
  14.  
  15.  
and i implimented it with this event in order for it to execute and i have it output the number to a textbox to make sure it's running correct... and i runs correctly, so i'm happy:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         GetFileCount("../")
  3.         TextBox2.Text = GetFileCount("../")
  4.     End Sub
  5.  
Jun 8 '07 #3
replace the "../" with what ever file folder you want to deal with.
Jun 8 '07 #4
Dököll
2,364 Expert 2GB
replace the "../" with what ever file folder you want to deal with.
You're a gentleman and scholar, thumper5, and good of you to post what you find out...

Good luck with the project:-)
Jun 8 '07 #5

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

Similar topics

10
by: hendafe | last post by:
I have a problem of importing a text file into Access. The text file will be imported using a delimiter, say ( , ) for example. This should be imported into the database. An example is: John,...
7
by: Diggler | last post by:
I have a web application that allows a user to manage files on the server. On the page is a counter that tells them how many files are in their folder. When you delete a file from the folder using...
3
by: Silvester | last post by:
I need to trigger some code when user drags and drops an entire folder onto my form. How can I distinguish between a folder drop and files dropped ? Can someone point me to code or a sample,...
5
by: Justin Fancy | last post by:
Hi Everyone, I am developing a file aging program that will eventually report on every folder that is in the root directory. I have a list of requested years, and counters set up to count every...
6
by: rlntemp-gng | last post by:
I need to extract information from some Excel files but am stuck with part of it: As an example, I have the following Excel File that has 3 tabbed sheets: FileName: ...
11
by: alivip | last post by:
how to ingrate my code to read text in in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name Camry and...
2
by: Salad | last post by:
In A2003 one can create a linked table using File/GetExternalData/Link/Exchange(). It's a nice feature but by and large fairly useless if I am reading the table structure correctly. The From &...
6
by: deve8ore | last post by:
Hello, We have a vendor that will supply us many files, and unfortunately will place them in different folders with no uniformity (within Windows Explorer). I'd like to have the capability to...
0
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
Hello group. I've migrated from Win 2003 server to Win 2008 server. I've been banging my head agaist a wall for several days now trying to figure this out. I have the following script that will...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.