Thanks for your response. This really helps. Unfortunately, I'm stuck
with what I'm trying to do next. I want to see if the files specified
in the arguments exist, using the FileExists function. However, I don't
know what reference to use to import System.File.IO (as I said, I'm new
to this). Next, I want to read each byte in the input file and write it
to the output file if it's less than 128 (ascii). Is this relatively
simple?
Actually, it is
Here is some air-code, this untested, and is infact not
likely to work the first try... I might have my indexing off or some minor
syntax issues, but it should be enough to get you started
Option Explict On
Option Strict On
Imports System
Imports System.IO
Public Function Main (ByVal args() As String) As Integer
' args contains all the arguments passed to your application
' assuming that the arguments are correct (you'll want to put
' in validation/parsing code here...
Dim inputFile As String = args(0)
Dim outputFile As String = args(1)
Dim anExiteCode As Integer = 0
Dim inBuffer() As Byte = new Byte(2048)
Dim outBuffer() As Byte = new Byte(2048)
Dim bytesRead As Integer = 0
dim bytesWritten = 0
Try
Using inFile As New FileStream(inputFile, FileMode.Open, FileAccess.Read), _
outFile As New FileStream(ouputFile, FileMode.Create, FileAccess.Write)
bytesRead = inFile.Read(inBuffer, 0, inBuffer.Length)
while bytesRead > 0
for i as integer = 0 to bytesRead - 1
if inbuffer(i) > 128 then
outBuffer(bytesWritten) = inbuffer(i)
bytesWritten += 1
end if
next i
outFile.Write(outBuffer, 0, bytesWritten)
bytesRead = inFile.Read(inBuffer, 0, inBuffer.Length)
end while
End Using
Catch ex As Exception
anExitCode = 1
End Catch
' You will most likely want to return an exit code
' 0 means no error, non-zero means a problem - you might
' want to have different codes for different problems, but
' that's up to you. You don't have to do this at all
' you could make Main a sub instead of a function, but
' most command line apps return an exit code to the OS -
' so it's a good idea to do the same.
Return anExitCode
End Function
Anyway, hth