How can I count all the files from a directory (and from subfolders) :confused:
Printable View
How can I count all the files from a directory (and from subfolders) :confused:
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 .
use dir() function
:wave: Pirate... have you got some idea about... iterate method :rolleyes:
There must be a previous thread on this forum on recursive search method . Try a search ...
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
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 .Quote:
Originally posted by PaloukiLook
The FolderBrowserDialog does not exist in Visual Studio 2002.
What can i do for this?
Because i am new in VB i don't understand what do you mean exactly.
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 .
thanks Pirate :wave:
:p Believe ought, the question has reply. I am greatly indebted for your help.