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 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####