Directory printer

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Directory printer
clanc789
Hey Coders,

I got a problem. I also want to learn how to program in an console application and this is the whole code I got so far:
Code: Select all
Module main
    Dim dir As String

    Sub Main()
        Try
            Console.Title = "Directory Printer"
            Console.Write("Directory to list: ")
            dir = "dir " & CType(Console.ReadLine(), Char)
            Shell(dir, AppWinStyle.NormalFocus, True, -1)
            Console.ReadLine()
        Catch ex As Exception
            Console.WriteLine(ex)
            Console.Read()
        End Try
    End Sub
End Module
The error I get an error that the file can not be found at the Shell(dir, .....) line. I dont want it to find files but I want it to list the directories via the shell (that is how I make the program send strings via cmd.exe right?).

Anybody can help me out?
Practice makes perfect!

VIP since: 6-10-2011
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Directory printer
comathi
Code: Select all
Dim dir As New IO.DirectoryInfo("C:\")
Dim folders() As IO.DirectoryInfo=dir.GetDirectories()
Dim folder As IO.DirectoryInfo

For Each folder in folders
console.WriteLine(folder.FullName)
Next
Last edited by comathi on Sat Dec 01, 2012 4:54 pm, edited 1 time in total.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Directory printer
mandai
For something simple like listing directories it would be easier to use the built-in DirectoryInfo.GetDirectories function rather than using the output from cmd.exe.
The above code should let you do this, though there is a typo on the 3rd line.
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Directory printer
comathi
mandai wrote:
The above code should let you do this, though there is a typo on the 3rd line.
My bad. It's fixed now.
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: Directory printer
clanc789
mandai wrote:
For something simple like listing directories it would be easier to use the built-in DirectoryInfo.GetDirectories function rather than using the output from cmd.exe.
The above code should let you do this, though there is a typo on the 3rd line.
First of all: thanks Comathi! That kinda works. But im still figuring on something so who knows I might succeed :D

To Mandai: ill try that today as well :)
Thx for the fast help guys! I hope I can solve it like this :D
Practice makes perfect!

VIP since: 6-10-2011
5 posts Page 1 of 1
Return to “Coding Help & Support”