Groups | Blog | Home
all groups > dotnet academic > september 2005 >

dotnet academic : Where is the console



thejamie
9/12/2005 4:53:01 AM
I am trying to see the results that occur when using a line such as
Console.WriteLine

The sample below comes directly from the Microsoft Help on GetFiles. I
cannot figure out where the Console.Writeline information is viewable. If I
am not supposed to see it then why doesn't the example use debug.write
instead of Console.WriteLine?

Imports System
Imports System.IO

Public Class Test
Public Shared Sub Main()
Try
Dim di As DirectoryInfo = New DirectoryInfo("c:\")
'Get only subdirectories that contain the letter "p."
Dim dirs As DirectoryInfo() = di.GetDirectories("*p*")
Console.WriteLine("Number of directories with a p: {0}",
dirs.Length)
Dim diNext As DirectoryInfo
' Count all files in each subdirectory that contain the letter
"e."
For Each diNext In dirs
Console.WriteLine("The number of files in {0} with an e is
{1}", _
diNext, diNext.GetFiles("*e*").Length)
Next

Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class

--
Regards,
thejamie
9/12/2005 5:16:05 AM
I think I understand now. If I want to see the result, then nothing has
changed. I still need to use Debug.Write instead of Console.Write. I
generally debug in the environment. I am greatly anticipating the
improvement that will come with VS 2005. Meanwhile, I stop the IDE, examine
the object's properties and make guesses as to what the code should look
like. Who has the time to compile and then run?

Thanks for your answer Peter.
--
Regards,
Jamie


[quoted text, click to view]
thejamie
9/12/2005 5:56:04 AM
I was actually looking for a good FileExists routine. Managed to create my
own. Listing below if needed by anyone:

Public Function FileExists(ByVal strPathName As String) As Short

'Dim bFind As System.IO.DirectoryInfo.GetFiles
Dim sDir As String
Dim nI As Integer
Const DirSep = "\"
Dim folders() As String
Dim file As System.IO.FileInfo

'Break up the file name
folders = Split(strPathName, DirSep, -1)

'build the directory
For nI = 0 To UBound(folders) - 1
sDir = sDir & folders(nI) & DirSep
Next

Dim dirs As New System.IO.DirectoryInfo(sDir)
Dim files() As System.io.FileInfo = dirs.GetFiles("*.*")

'get the files that match the parameters
files = dirs.GetFiles(folders(UBound(folders)))

'check for a match
If Not (files Is Nothing) Then
For Each file In files
If LCase(file.FullName) = LCase(strPathName) Then
FileExists = True
Exit For
End If
Next
End If

End Function


--
Regards,
Jamie

Peter van der Goes
9/12/2005 7:05:57 AM

[quoted text, click to view]

What template did you use for the project? If you use a VB Console project
and substitute the code you quoted for the boilerplate code, it compiles and
displays the output in the console window.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Ron
10/12/2005 3:15:07 PM
or you can just use System.IO.File.Exists(filename)

[quoted text, click to view]
thejamie
10/13/2005 5:46:03 AM
I love it when things are easy. Those dang forests keep getting in the way
of the trees.
--
Regards,
Jamie


[quoted text, click to view]
thejamie
11/4/2005 4:12:02 AM
Knew there was a reason I wrote my own. The behavior of Fileexists isn't
what I was looking for. The VB6 code accepts a filename including directory.
The one I wrote does. When I tried doing the same with the FileExists
property, it wasn't accepting the path.
--
Regards,
Jamie


[quoted text, click to view]
Cyril Gupta
12/8/2005 6:29:55 AM
I think the scripting FileExists does accept full path (including directory
name). I am using it in one of my projects right now and I have no
complaints.

Earlier I used another easy method of finding whether a file exists or not.
The Dir method, of course it is not as powerful as fileexists and there is a
flaw in that approach, one that I came across but I can't remember it now. I
think it had something to do with the way it accesses directories.

Regards

AddThis Social Bookmark Button