P
pritesh_b
Guest
When I try to add the following to :
Public Shared Sub ProcessFile(ByVal path As String)
Dim i As Integer
For i = 0 To 100000
_files(i) = path
Next
End Sub ProcessFile
ReadOnly Property speed()
Get
Return _files()
End Get
End Property
I get the following error:
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
I have found some code which is exactly what I need but I dont know how to
get a return value i.e. add the filenames to a variable.
Can some one please explain to me how this is done?
Thanks
Here is the code I found:
For Directory.GetFiles and Directory.GetDirectories
For File.Exists, Directory.Exists
Imports System
Imports System.IO
Imports System.Collections
Takes an array of file names or directory names on the command line.
Determines what kind of name it is and processes it appropriately
Public Class RecursiveFileProcessor
Dim _fileLocations As String
Entry point which delegates to C-style main function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
Dim path = "M:\static\core\ssi\V3.3.4"
End Sub
Public Overloads Shared Sub Main(ByVal args() As String)
Dim path As String
For Each path In args
If File.Exists(path) Then
This path is a file
ProcessFile(path)
Else
If Directory.Exists(path) Then
This path is a directory
ProcessDirectory(path)
Else
Console.WriteLine("{0} is not a valid file or
directory.", path)
End If
End If
Next path
End Sub Main
Process all files in the directory passed in, and recurse on any
directories
that are found to process the files they contain
Public Shared Sub ProcessDirectory(ByVal targetDirectory As String)
Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
Process the list of files found in the directory
Dim fileName As String
For Each fileName In fileEntries
ProcessFile(fileName)
Next fileName
Dim subdirectoryEntries As String() =
Directory.GetDirectories(targetDirectory)
Recurse into subdirectories of this directory
Dim subdirectory As String
For Each subdirectory In subdirectoryEntries
ProcessDirectory(subdirectory)
Next subdirectory
End Sub ProcessDirectory
Real logic for processing found files would go here.
Public Shared Sub ProcessFile(ByVal path As String)
Console.WriteLine("Processed file {0}.", path)
End Sub ProcessFile
End Class RecursiveFileProcessor
---------------------------------------------------
Pritesh