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.
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
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:
Anybody can help me out?
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
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?).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
Anybody can help me out?
Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
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.
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.
The above code should let you do this, though there is a typo on the 3rd line.
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.
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.First of all: thanks Comathi! That kinda works. But im still figuring on something so who knows I might succeed
The above code should let you do this, though there is a typo on the 3rd line.

To Mandai: ill try that today as well

Thx for the fast help guys! I hope I can solve it like this

Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023