Hi guys
I am trying to make a simple console application for deleting files which are N days old and the console application should take three switches like following:
deleteoldfiles -dFolder C:\myfolder -fType *.dmp -nDays 3
The below module does it, however I am not sure whether the logic used to capture the switch values is appropriate or standard. Please help
I am trying to make a simple console application for deleting files which are N days old and the console application should take three switches like following:
deleteoldfiles -dFolder C:\myfolder -fType *.dmp -nDays 3
The below module does it, however I am not sure whether the logic used to capture the switch values is appropriate or standard. Please help
VB.NET:
Imports System.Console
Imports System.IO
Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Text
Imports System.Environment
Module Module1
Sub Main()
Dim strStartupArguments() As String, intCount As Integer
Dim fldrName As String, fileType As String, nDays As Integer
strStartupArguments = System.Environment.GetCommandLineArgs
For intCount = 0 To UBound(strStartupArguments)
' Console.WriteLine(strStartupArguments(intCount).ToLower)
' Console.WriteLine(strStartupArguments(intCount))
Select Case strStartupArguments(intCount).ToLower
Case "-dfolder"
' fldrName = strStartupArguments(intCount).ToLower
fldrName = strStartupArguments(intCount + 1)
'Console.WriteLine(fldrName)
Case "-ftype"
fileType = strStartupArguments(intCount + 1)
'Console.WriteLine(fileType)
Case "-ndays"
nDays = strStartupArguments(intCount + 1)
End Select
Next intCount
Try
' For Each file As IO.FileInfo In New IO.DirectoryInfo("D:\Documents").GetFiles("*.pdf")
For Each file As IO.FileInfo In New IO.DirectoryInfo(fldrName).GetFiles(fileType)
' Console.WriteLine((Now - file.CreationTime))
If (Now - file.CreationTime).Days > nDays Then file.Delete()
Next
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
End Sub
End Module