|
-
Dec 24th, 2003, 08:38 AM
#1
Thread Starter
New Member
Count Files from Directory
How can I count all the files from a directory (and from subfolders)
Last edited by KesmpedanSkilos; Dec 24th, 2003 at 08:51 AM.
-
Dec 24th, 2003, 09:36 AM
#2
Sleep mode
Use Length or Count( either ways if exist) to get the number returns from specified method like GetFiles here :
VB Code:
Dim files As Integer = IO.Directory.GetFiles("C:\CPoint\CSharpEd").Length
MessageBox.Show(files.ToString)
You need recursive method to iterate through all folders and subfolders in a path .
-
Dec 24th, 2003, 09:37 AM
#3
Fanatic Member
-
Dec 24th, 2003, 01:03 PM
#4
Thread Starter
New Member
Need more help
Pirate... have you got some idea about... iterate method
-
Dec 24th, 2003, 06:08 PM
#5
Sleep mode
There must be a previous thread on this forum on recursive search method . Try a search ...
-
Dec 24th, 2003, 09:54 PM
#6
Frenzied Member
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dir As New FolderBrowserDialog
Dim totalFiles As Integer
If dir.ShowDialog = DialogResult.OK Then
TotalFilesInDirectory(totalFiles, dir.SelectedPath)
End If
End Sub
Private Sub TotalFilesInDirectory(ByRef totalFiles As Integer, ByVal dirPath As String)
Dim dir As New IO.DirectoryInfo(dirPath)
totalFiles += dir.GetFiles().Length
For Each _dir As IO.DirectoryInfo In dir.GetDirectories()
TotalFilesInDirectory(totalFiles, _dir.FullName)
Next
End Sub
-
Dec 25th, 2003, 05:39 AM
#7
Junior Member
The FolderBrowserDialog does not exist in Visual Studio 2002.
What can i do for this?
-
Dec 25th, 2003, 05:44 AM
#8
Sleep mode
Originally posted by PaloukiLook
The FolderBrowserDialog does not exist in Visual Studio 2002.
What can i do for this?
Then just provide full folder path or use SpecialFolder enums in System.Environmen Namespace .
Last edited by Pirate; Dec 25th, 2003 at 06:37 AM.
-
Dec 25th, 2003, 05:48 AM
#9
Junior Member
Because i am new in VB i don't understand what do you mean exactly.
-
Dec 25th, 2003, 06:07 AM
#10
Sleep mode
VB Code:
MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles))
Ex. I would change Kovan's code to this :
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dir As String
dir = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
Dim totalFiles As Integer
TotalFilesInDirectory(totalFiles, dir)
End Sub
Private Sub TotalFilesInDirectory(ByRef totalFiles As Integer, ByVal dirPath As String)
Dim dir As New IO.DirectoryInfo(dirPath)
totalFiles += dir.GetFiles().Length
For Each _dir As IO.DirectoryInfo In dir.GetDirectories()
TotalFilesInDirectory(totalFiles, _dir.FullName)
Next
End Sub
This will search program files folder , you can change program files to any value in the SpecialFolder Enum . Or supply your own path . Note that this for local system disk .
-
Dec 25th, 2003, 06:27 AM
#11
Junior Member
thanks Pirate
-
Dec 25th, 2003, 09:21 AM
#12
Thread Starter
New Member
The End
Believe ought, the question has reply. I am greatly indebted for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|