473,385 Members | 2,028 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.

No of files in folder

Hi

I want to know how many files exist in a folder. I will use the number of
files to set the size of a string array which will contain the names of the
files. The array part I've done but need to know how to work out the number
of files in the folder. I'm currently using an arbitrary figure (40) but am
concerned that at some stage the number of files will exceed the size I've
set for the array

Thanks

Michael Bond
Jul 5 '06 #1
4 1120

mabond wrote:
Hi

I want to know how many files exist in a folder. I will use the number of
files to set the size of a string array which will contain the names of the
files. The array part I've done but need to know how to work out the number
of files in the folder. I'm currently using an arbitrary figure (40) but am
concerned that at some stage the number of files will exceed the size I've
set for the array
Here's one way to do it.

Dim di as DirectoryInfo
Dim aFiles() as String

di = new DirectoryInfo("myDirectoryPath")
aFiles = di.GetFiles
MessageBox.Show("Contains " & cstr(aFiles.Count) & " files")

Jul 5 '06 #2
Hi

getting the following build error when I use this

"Value of type '1-dimensional array of System.IO.FileInfo' cannot be
converted to '1-dimensional array of String' because 'System.IO.FileInfo' is
not derived from 'String'."

Any ideas

Michael
"za***@construction-imaging.com" wrote:
>
mabond wrote:
Hi

I want to know how many files exist in a folder. I will use the number of
files to set the size of a string array which will contain the names of the
files. The array part I've done but need to know how to work out the number
of files in the folder. I'm currently using an arbitrary figure (40) but am
concerned that at some stage the number of files will exceed the size I've
set for the array

Here's one way to do it.

Dim di as DirectoryInfo
Dim aFiles() as String

di = new DirectoryInfo("myDirectoryPath")
aFiles = di.GetFiles
MessageBox.Show("Contains " & cstr(aFiles.Count) & " files")

Jul 5 '06 #3
Dim counter As _
System.Collections.ObjectModel.ReadOnlyCollection( Of String)
counter = My.Computer.FileSystem.GetFiles("C:\TestDir")
MsgBox("number of files is " & CStr(counter.Count))

Taken from:
http://msdn2.microsoft.com/en-us/library/wt8k42e9.aspx

Jul 5 '06 #4
Hi

I'm now going with

'Dim di As DirectoryInfo = New DirectoryInfo(pPath)
'Dim aFiles()
'aFiles = di.GetFiles

'Dim arraysize As Integer = aFiles.Length
'array = New String(arraysize, 1) {}

And it works. Thnaks for pointing me in the right direction.

Regards

Michael Bond
"za***@construction-imaging.com" wrote:
>
mabond wrote:
Hi

I want to know how many files exist in a folder. I will use the number of
files to set the size of a string array which will contain the names of the
files. The array part I've done but need to know how to work out the number
of files in the folder. I'm currently using an arbitrary figure (40) but am
concerned that at some stage the number of files will exceed the size I've
set for the array

Here's one way to do it.

Dim di as DirectoryInfo
Dim aFiles() as String

di = new DirectoryInfo("myDirectoryPath")
aFiles = di.GetFiles
MessageBox.Show("Contains " & cstr(aFiles.Count) & " files")

Jul 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rosa | last post by:
Hi, I'm trying to clear the TIF on Windows XP programmatically with the below code. This code works fine on any folder but the TIF. For some reason the atEnd() statements always defaults to true...
8
by: Adam Clauss | last post by:
I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to get them all added to the solution. Preferable would be that the...
2
by: Dan Baker | last post by:
I'm relatively new to the .cs world. I would like to have some "shared" .cs files, which several solutions can use. I don't want to place these in a ..dll, I simply want them included into...
2
by: Glen | last post by:
As I understand it, when the first page of an application is accessed, all ASPX/ASCX/etc. files in the same folder are compiled using the JIT compiler. Is there a way to turn this feature off? ...
8
by: vinesh | last post by:
I have sample Asp.Net Web Application project. Let me know how to keep the files related to this project (like the webform.aspx, WebForm1.aspx.vb, WebForm1.aspx.resx) in a separate folder within a...
8
by: Paw | last post by:
Greetings. I use asp. what I need is is when a visitor comes to the site, I need it to check the host name. if "www.hometowndigest.com" is the host, then check a folder named "something" and if...
5
by: wwwmike | last post by:
I have an asp.net 2.0 application where I move about 200,000 text files daily in and out. When using VS 2005 to debug my application everything works find if only a few files are in the folder....
3
by: jaeden99 | last post by:
I was wandering if nyone has a script to move files older than x days old? i've seen several to delete, but I don't want to delete. I would like to create a backup of the files first verify with...
1
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus spreading them across multiple folders. For instance if we have 100,000 files to be copied, Do we copy all of them to...
8
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
Hello group. I have some code (given to me), but I don't know alot about ASP, so I was hoping someone here can help. Running on Win 2008 server. The code below will scan a folder and subfolder...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.