|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Question about walking the file systemHello Everyone,
I am building an application and I need to walk the file system from the root directory on down. I need to cover every single directory on the system and all of their sub directories. Basically, I am trying to programatically obtain a count of how many files the system has. Any ideas on how to walk the filesystem in VB.NET or if there is a better way to get a file count? Thanks! Anthony I would google for a recursive search code. Then have it count files inseat
of listing it. I have found the code on http://www.vb.net Hope this helps. Anthony P. wrote:
> Hello Everyone, On the 14th of October, Stephany Young posted in a reply to "Find Files > > I am building an application and I need to walk the file system from > the root directory on down. I need to cover every single directory on > the system and all of their sub directories. Basically, I am trying to > programatically obtain a count of how many files the system has. > > Any ideas on how to walk the filesystem in VB.NET or if there is a > better way to get a file count? > > Thanks! > Anthony > and Folders", the following code which might be helpful - File.WriteAllText([output filename], String.Join(Environment.Newline, Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories))) See the OP for full details. ShaneO There are 10 kinds of people - Those who understand Binary and those who don't. ShaneO <spc***@optusnet.com.au> wrote in news:4536f02a$0$24796$afc38c87
@news.optusnet.com.au: > File.WriteAllText([output filename], String.Join(Environment.Newline, Doesn't this method take a while for the function to return results? So you > Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories))) > > See the OP for full details. can't display progress? Shane0 was a bit previous in posting that snippet in this context.
While it was perfectly valid for thr thread concerned it is not appropriate for this case. The OP is asking how to get a count of the files on a given disk drive. Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories).Length will certainly give that count BUT it also returns a string array with an element for each file which could be rather large and possibly blow out some resource or other. It will also throw an exception if it encounters a folder with restrictive permissions, so if you start from the root of a disk drive e.g. C:\, it will blow up when it hits the System Volume Information folder. I don't think there is 'quick' way to get this information and a recursive procedure would be more appropriate. Show quoteHide quote "Spam Catcher" <spamhoneypot@rogers.com> wrote in message news:Xns986120691EF2Dusenethoneypotrogers@127.0.0.1... > ShaneO <spc***@optusnet.com.au> wrote in news:4536f02a$0$24796$afc38c87 > @news.optusnet.com.au: > >> File.WriteAllText([output filename], String.Join(Environment.Newline, >> Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories))) >> >> See the OP for full details. > > Doesn't this method take a while for the function to return results? So > you > can't display progress? "Anthony P." <papill***@gmail.com> wrote in news:1161221509.166876.283380 @h48g2000cwc.googlegroups.com:> Any ideas on how to walk the filesystem in VB.NET or if there is a You can use system.io but i found it to slow - rather ... the Windows API > better way to get a file count? seems to be much faster.
Show quote
Hide quote
"Anthony P." <papill***@gmail.com> wrote in message I'm not saying its the most efficient code, but I leeced if from somewhere news:1161221509.166876.283380@h48g2000cwc.googlegroups.com... > Hello Everyone, > > I am building an application and I need to walk the file system from > the root directory on down. I need to cover every single directory on > the system and all of their sub directories. Basically, I am trying to > programatically obtain a count of how many files the system has. > > Any ideas on how to walk the filesystem in VB.NET or if there is a > better way to get a file count? > > Thanks! > Anthony > and it works Public FileArray As New ArrayList Private Sub Recurse(ByVal DirPath As String, ByVal IncludeSubFolders As Boolean) Dim objFileInfo As FileInfo Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath) Dim objSubFolder As DirectoryInfo Try ' This bit does the getting of files in the current folder Console.WriteLine("Processing Folder: " & objDir.FullName) StsCurrentFile.Text = "Processing Folder: " & objDir.FullName For Each objFileInfo In objDir.GetFiles() Console.WriteLine("Processing File: " & objFileInfo.Name & vbTab & objFileInfo.LastWriteTime) FileArray.Add(objFileInfo) Next ' This bit does the recursion for subdirs If IncludeSubFolders Then For Each objSubFolder In objDir.GetDirectories() Console.WriteLine("Processing Subfolder: " & objDir.FullName) 'Console.WriteLine(Recurse(objSubFolder.FullName, IncludeSubFolders)) Recurse(objSubFolder.FullName, IncludeSubFolders) Next End If Catch Ex As Exception MsgBox("Err - " & Err.Number & vbNewLine & vbNewLine & Err.Description & vbNewLine & vbNewLine & Err.GetException.StackTrace & vbNewLine & vbNewLine & Err.Source & vbNewLine & vbNewLine & Err.GetException.Source) End Try End Sub
main menu disappearred
If comparision operator is one of these or contains ? VB 2005 Form Controls Disappeared!! Table Adapter Update Method UTF-8 encoding problem Read another applications textboxes (VB 2005) using a triple-nested for...next loop Rounding issue need help!! Incomplete Escaping Functionality?? |
|||||||||||||||||||||||