Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

total files in a directory 2

Status
Not open for further replies.

VBRookie

Programmer
May 29, 2001
331
US

Hi,

I'm creating a web app that will allow users to upload images to a directory on the server. What I'd like to do (to prevent having 5000 files in one directory) is to set a limit on how many files can go in one directory and once that limit is reached create a new directory and start storing files there.

Does that make sense? So once directory A has, lets say, 300 files in it ... directory B will be created and so on.

Is there anyway to get the file count without iterating through each file in the directory? That could be kind of slow. I don't see many options outside of that though.

Any suggestions or does anyone have a better idea on how to accomplish this altogether? I'm certainly open to ideas.

Many Thanks,
- Vb Rookie
 
Dim dirToList As String = "...path to check..."

Dim dir As DirectoryInfo = New DirectoryInfo(dirToList)

Dim files() As System.IO.FileInfo

files = dir.GetFiles()

If files.lentth >= <your amount> then
'Create New Directory ...
End IF


Jim

 
You could also shorten that method down to:
Code:
        If System.IO.Directory.GetFiles("c:\temp").Length >= 300 Then

        End If
and if you are using version 2.0 of the framework and VB.NET, you can use the My namespace which is basically another route to the same classes:
Code:
        If My.Computer.FileSystem.GetFiles("c:\temp").Count > 300 Then

        End If


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 

Thanks ca8msm! That works beautifully!

- VB Rookie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top