473,395 Members | 1,726 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,395 software developers and data experts.

Question about walking the file system

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

Oct 19 '06 #1
8 1570
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.
Oct 19 '06 #2
You can also try:

http://www.planetsourcecode.com/
Oct 19 '06 #3
Thank you very much! Very helpful.

Anthony

Oct 19 '06 #4
Anthony P. wrote:
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
On the 14th of October, Stephany Young posted in a reply to "Find Files
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.
Oct 19 '06 #5
"Anthony P." <pa*******@gmail.comwrote in news:1161221509.166876.283380
@h48g2000cwc.googlegroups.com:
Any ideas on how to walk the filesystem in VB.NET or if there is a
better way to get a file count?
You can use system.io but i found it to slow - rather ... the Windows API
seems to be much faster.
Oct 19 '06 #6
ShaneO <sp****@optusnet.com.auwrote 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?
Oct 19 '06 #7
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.
"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
ShaneO <sp****@optusnet.com.auwrote 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?

Oct 19 '06 #8

"Anthony P." <pa*******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.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
I'm not saying its the most efficient code, but I leeced if from somewhere
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
Oct 21 '06 #9

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

Similar topics

4
by: WindAndWaves | last post by:
Hi Gurus I hope I am going to make sense with this question: I have an html page that I have turned into a php page with a bit of php code above the html (connect to database, massage data a...
4
by: Jim Bancroft | last post by:
Sorry for the basic nature of this question. I know XSL can do this, but I don't recall a good method... Say I have an xml structure like this: <folder_structure> <folder name="folder1">...
3
by: Dr. Indera | last post by:
hi, this may be a bit long, but i want to make sure i explain my questions. (aka, not real experienced with visual studio.net) i'm using visual studio.net 2003 (visual basic.net and crystal...
62
by: ROSY | last post by:
hello experts plz answer following questions::: thanks in advance. 1. Out of fgets() and gets() which function is safe to use and why? 2. What is a far pointer? where we use it? 3. What does the...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
1
by: Zachary Hartnett | last post by:
I was trying to write a routine this morning that would open a given assembly, walk the inheritance tree of classes in the assembly, and provide a list of classes in the assembly that inherit from...
6
by: Jackson | last post by:
I've got an inheritance question and was hoping brighter minds could guide me. I am in the strange situation where some of the methods in a subclass are actually more general than methods in a...
2
by: =?Utf-8?B?YW5rMmdv?= | last post by:
Thanks in advance for reading this. Let's say I have a file (file01) with this data in ASCII (ignore line col): line01 123abc line02 Header01 Starts blah var line03 detail01 000001...
10
by: Francois Malgreve | last post by:
Hello everybody, I have a pretty straightforward question regarding namespace. Is there anyone who knows why the following code does not compile on the line Type t =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.