Question Searching WIN 7 DIRs w/Visual Basic.NET 2003

gremlinkurst

New member
Joined
Jan 24, 2013
Messages
2
Location
In the same city where the Alamo mission is locate
Programming Experience
1-3
Some background first, so you can see where I'm coming from (have patience, please): I started studying Logic and Algorithm Structures in BASIC when it was still an Instruction Programming Language; this was before QBASIC existed, before I learned of Visual Basic (not Visual Basic.NET). Several years later I got interested in C#, C++, and Visual Basic.NET. I've administered every Windows platform from Windows 95 to Windows 7, as well as a VAX-VMS 11 mainframe. I've got a couple of Microsoft certifications, but they're old and don't mean much anyway, especially the Network Administration (so MUCH has changed!). Oh, and I've also learned several Unix/Linux operating systems as well.

After a long time of not coding, I'm getting back into "the game;" I never did it professionally, exactly...but, I did work at Lamar University in Beaumont, Texas as a computer laboratory instructor. Anyhow, I'm breaking out my 2003 box/edition of Visual Basic.NET and am going to get a DIY refresher in the subject. Time and trauma-induced brain damage has robbed me of much of what I once knew, so I have to re-learn a lot of stuff much as a beginner would, but because of my experience, it wouldn't take nearly as long. Anyway, I have an idea for a learning project that I need some help with; I want to try to tailor my re-learning path to proceed along relevant, practical lines in the Windows world (not that many folks are selling the things I'm interested in buying on Linux platforms, but learning this stuff on Windows would have been easier if I'd STARTED on Unix).

The generally specific thing (oxymoron intended) I'd like to know is how do I get started working with Windows file systems from within a Visual Basic.NET application? The exact thing I need to know is how is VB.NET code implemented to look in Windows directories? I know how to get/search data contained in a specific FILE or matrix within a VB.NET project, but I have no idea, for instance, how to get it to find all items (excepting items in sub-directories) in this hypothetical directory: C:\Texts\, or the non-hypothetical directory: C:\ (again, excepting items in sub-directories), to get the same kind of information that Firefox gets when you instruct it to navigate a specific file path (see attached PNG).
PNG.png
The matrix to temporarily store such limited data would be very simple to construct (that's NOT what I need assistance with); once I GET the data, I would know what to do with it (filter, manipulate, et cetera). I'm looking for code segments/snippets that illustrate the reading of Windows directories without considering nested directories (once I get the elemental concept I can then proceed to more complex structures). Being really anal about external and internal documentation (there are few things I detest more than an ironic and utter absence of information in or about a data package), of course I would cite contributors' efforts (in the event I share the results with others), even if the help was only being given a good URL or two. That's what I'm really asking for: Where, exactly, would I go on the 'net to find code examples of the type I'm talking about? My personal queries have been so abstrusely specific that I get VERY few returns, and NONE of them are relevant.

P.S.: I use "matrices" here as some may understand to be "indices." (or "indexes" to the less erudite)
 
Last edited:

IanRyder

Well-known member
Joined
Sep 9, 2012
Messages
1,130
Location
Healing, NE Lincs, UK
Programming Experience
10+
Hi,

Here are a couple of things for you:-

1) MSDN has a wealth of information when it comes to figuring out anything to do with programming in .NET. To get going with directory and file information in the windows operating system that have a look at this article:-

DirectoryInfo Class (System.IO)

2) On the basis that you are refreshing your knowledge and "Breaking Out" the old 2003 VB.NET box then I would suggest that you leave the old box where it is and jump straight to the newest version of VB.NET thereby gaining the advantage of refreshing your knowledge to include the latest technologies available to you. You can download Visual Studio Express 2012 for Free and then you can get a product key for the software just by registering. Have a look here:-

http://www.microsoft.com/visualstudio/eng#downloads

Hope that helps and good luck.

Cheers,

Ian
 

gremlinkurst

New member
Joined
Jan 24, 2013
Messages
2
Location
In the same city where the Alamo mission is locate
Programming Experience
1-3
Thank you for your information, specifically (just what I needed!) DirectoryInfo Class (System.IO) . I understand what you mean about the old vb.net, but it is legal and fully featured/functional, unlike the legal but not quite as versatile EXPRESS packages ("Express" is supposed to sound good, but it's not an IDE the likes of which are available in the Pro editions). The old one is still good and backwards-compatible with more advanced versions of Windows (when users download an install the required runtime environments, etc), but I can't quite afford the new 2012 non-Express license. What I WILL do with the express version is use it to learn what's new before I actually buy the more powerful studio package. Hey, THIS ought to give you a laugh: I have a REALLY old Visio Professional 5.0...I don't even know if it'll run on my current system. But, yeah, I'm gonna have to up[date my MSDN library for sure...and have you SEEN how much they want nowadays? $1,200 for a new 2012 pro studio--WOW!!!
 
Last edited:

IanRyder

Well-known member
Joined
Sep 9, 2012
Messages
1,130
Location
Healing, NE Lincs, UK
Programming Experience
10+
Hi,

Yeah it's all way expensive, I know, but then that is why they are billionaires and we are not. I cannot give you any advice on the Express version myself since I am on VS 2010 Ultimate, but what you will find is that there seems to be a lot of people that are using the Express version so maybe you should create a Thread in the Chit Chat forum and ask people for their opinions and experience.

Good luck and cheers,

Ian
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
Thank you for your information, specifically (just what I needed!) DirectoryInfo Class (System.IO) . I understand what you mean about the old vb.net, but it is legal and fully featured/functional, unlike the legal but not quite as versatile EXPRESS packages ("Express" is supposed to sound good, but it's not an IDE the likes of which are available in the Pro editions). The old one is still good and backwards-compatible with more advanced versions of Windows (when users download an install the required runtime environments, etc), but I can't quite afford the new 2012 non-Express license. What I WILL do with the express version is use it to learn what's new before I actually buy the more powerful studio package. Hey, THIS ought to give you a laugh: I have a REALLY old Visio Professional 5.0...I don't even know if it'll run on my current system. But, yeah, I'm gonna have to up[date my MSDN library for sure...and have you SEEN how much they want nowadays? $1,200 for a new 2012 pro studio--WOW!!!
In all honesty here, the VS2010 or VS2012 express editions will give you far more than your VS2003 Professional will, as far as IDE features go, so unless you're really wanting to up and buy one of the full editions, I'm sure you'll find the Express edition will suit you just fine. I happen to have VS 2010 Ultimate but I have yet to actually use it in a way that I couldn't with the Express editions, but since I got it for free (thanks to college) I just use it anyways.
I would also like to mention that VS2003 wont even install on Windows Vista, 7, or 8. One of the core components that they used in VS2002 and VS2003 isn't supported in the NT 6 and newer kernels, VS2005 can work in Windows 7 if you play with it enough to get it to work, VS 2008 works just fine with SP 1 installed and VS2010 and 2012 work out of the box (I highly recommend installing 2010 SP1 though). So going forward you might as well start off with 2010 or 2012 Express edition for 2 reasons: 1.) the low cost (free) and 2.) the IDE's actually work on modern operating systems. Some good news too, ever since VS2008 Microsoft has included a ".Net target" concept, which means in VS2008, 2010, & 2012 you can make an application that is compiled for any of the .Net versions from 2.0 and up to the .Net framework that was released with the version of VS (2.0, 3.0, 3.5, 4.0, & 4.5 respectively).

After that rant, your ultimate question of "How do I get a list of all files & folders in a folder?" is super simple to answer & the answer applies to all versions of .Net, just use:
System.IO.Directory.GetFiles() and System.IO.Directory.GetDirectories() respectively, or if you want an array that contains both files & folders then use Directory.GetFileSystemEntries()

Here's an example to get ya started:
Imports System.IO 'Added at the very top of the code file, above the "Public Class <FormName>" line

Private Sub DoDir(ByVal src As String)
    Try
        Dim Files() As String = Directory.GetFileSystemEntries(src)
        For Each element As String In Files
            If Directory.Exists(element) Then
                'If you want info on the current folder itself uncomment the two code lines below:
                'Dim di As New DirectoryInfo(element)
                'Do something with the folder
                'di = Nothing

                'If you want to recursively loop the folder, uncomment the line below:
                'Call DoDir(element)
            Else
                Try
                    Dim fi As New FileInfo(element)
                    'Do something with the file
                    fi = Nothing
                Catch ex As Exception
                    MessageBox.Show(ex.ToString, "DoDir_InnerLoop")
                End Try
            End If
        Next element
    Catch ex As Exception
        MessageBox.Show(ex.ToString, "DoDir")
    End Try
End Sub
 
Top Bottom