Create Directory every new month

As a general rule of thumb, you dont really want to name your directories simply after a month name for two main reasons:
1. In 12 months youre going to have a problem when its March again
2, The directories wont sort well

To fix both problems with 1 solution, I recomend you name your directories like so: 2004-03-March

Which will allow you proper sorting of yoru directories and still give you a human readable month name.
 
one really nice thing about the .Net system.io namespace it that there are all the functions needed to do this.


Imports system.IO

It NOT directory.exist("<directory name>") then
directory.create("<directory name>")
end if

the <directory name> can also include subdirectories.
IE say you need C:\Test1\Vb\Samples\Monday\11AM
and you do not even have a C:\Test1 directory by passing in all of the sub directories it will create them as well
 
Code:
Public Class DirMaker

    Public Function GenerateSaveDirString(ByVal Month As String, ByVal Day As String, ByVal Year As String) As String
        Dim Ret As String
        Dim Mon As String = ConvertMonth(Month)

        Ret = "C:\Imported\" & Mon & "-" & Year & "\" & Day & "\"

        If Not System.IO.Directory.Exists(Ret) Then
            System.IO.Directory.CreateDirectory(Ret)
        End If
        Return Ret
    End Function

    Public Function ConvertMonth(ByVal Month As String) As String
        Select Case Month
            Case 1 : Return "Jan"
            Case 2 : Return "Feb"
            Case 3 : Return "Mar"
            Case 4 : Return "Apr"
            Case 5 : Return "May"
            Case 6 : Return "Jun"
            Case 7 : Return "Jul"
            Case 8 : Return "Aug"
            Case 9 : Return "Sept"
            Case 10 : Return "Oct"
            Case 11 : Return "Nov"
            Case 12 : Return "Dec"
        End Select
    End Function
End Class
 
Back
Top