Newbie needs help with command line paramaters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have only been working with VB.NET for a couple of weeks. Can someone tell me how to get this to work
I want to be able to call a program 'KillOldFiles' with two command line variables Days and Directory

KillOldFiles 5,C:\tes

When the above is run it should check the c:\test directory for files older that 5 days old and delete them
I have found some references to System.Environment.GetCommandLineArgs() but cant figure out how it should work. Also is there a way to test/debug applications with command line paramaters

Thanks
Stev

#####Start Code####
Sub Main(ByVal DaysOld As Integer, ByVal FilePath As String

If Not IsNumeric(DaysOld) The
Exit Su
End I

If FilePath.Length = 0 The
Exit Su
End I

Console.WriteLine("Deleteing old files as specified"
' Create a reference to the current directory
Dim di As New System.IO.DirectoryInfo(FilePath
' Create an array representing the files in the current directory
Dim fi As System.IO.FileInfo() = di.GetFiles(
'Console.WriteLine("The following files exist in " & FilePath & " :"
' Print out the names of the files in the current directory
Dim fiTemp As System.IO.FileInf
For Each fiTemp In f
If Not fiTemp.CreationTime > DateAdd(DateInterval.Day, -(DaysOld + 1), Now()) The
'Console.WriteLine("delete older than: " & DaysOld & " Name: " & fiTemp.Name & " Time: " & iTemp.CreationTime
fiTemp.Delete(
'Els
'Console.WriteLine("keep newer than: " & DaysOld & " Name: " & fiTemp.Name & " Time: " & fiTemp.CreationTime
End I
Next fiTem

Console.WriteLine("Files Deleted"
End Sub 'mai
#####End Code####
 
I have only been working with VB.NET for a couple of weeks. Can someone tell me how to get this to work?
I want to be able to call a program 'KillOldFiles' with two command line variables Days and Directory.

KillOldFiles 5,C:\test

Actually, you'd probably want to do either:

KillOldFiles 5 C:\test

(NOTE: no commad) -- or get fancy and actually provide named-arguments
so they can be in any order:

KillOldFiles /d:5 /p:C:\test

Where "/d" is number of days and "/p" is path. The first option is
easier and requires less parsing.
When the above is run it should check the c:\test directory for files older that 5 days old and delete them.
I have found some references to System.Environment.GetCommandLineArgs() but cant figure out how it should work.

GetCommandLineArgs will return a string array. The first element (0)
will be the program name (killoldfiles.exe). After that, each element
will be the command line options entered. So in your case:

dim args() as string = Environment.GetCommandLineArgs()
' s(0) = "killoldfiles.exe"
' s(1) = "5"
' s(2) = "C:\test"
Also is there a way to test/debug applications with command line paramaters?

Right click on the project in Solution Explorer and select properties.
Click on "Configuration Properties" and then "Debugging". Under the
"Start Options" section should be a textbox labeled "Command Line Args".
Put your data there:

5 C:\temp
 
Steve said:
I have only been working with VB.NET for a couple of weeks. Can
someone tell me how to get this to work? I want to be able to call a
program 'KillOldFiles' with two command line variables Days and
Directory.

KillOldFiles 5,C:\test

When the above is run it should check the c:\test directory for files
older that 5 days old and delete them. I have found some references
to System.Environment.GetCommandLineArgs() but cant figure out how it
should work.

It returns an array of Strings. It is declard by writing

dim args as string()
Also is there a way to test/debug applications with
command line paramaters?

Enter them in the project properties.

#####Start Code#####
Sub Main(ByVal DaysOld As Integer, ByVal FilePath As String)

/Either/ use System.Environment.GetCommandLineArgs /or/ add the arguments to
sub Main, and if you do the latter, you must declare an array:

Sub Main(Args As String())

If Not IsNumeric(DaysOld) Then

If you declare an Integer variable, you don't have to check it for being
numeric.
Exit Sub
End If


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "=?Utf-8?B?U3RldmU=?= said:
I have only been working with VB.NET for a couple of weeks. Can someone tell me how to get this to work?
I want to be able to call a program 'KillOldFiles' with two command line variables Days and Directory.

KillOldFiles 5,C:\test

When the above is run it should check the c:\test directory for files older that 5 days old and delete them.
I have found some references to System.Environment.GetCommandLineArgs() but cant figure out how it should work. Also is there a way to test/debug applications with command line paramaters?

Thanks,
Steve

#####Start Code#####
Sub Main(ByVal DaysOld As Integer, ByVal FilePath As String)

.... see:

<URL:http://www.google.de/[email protected]>
 
Back
Top