Announcement

Collapse
No announcement yet.

Creating Folders by Date

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating Folders by Date

    I have this script that I found on MS site:
    strMonth = Month(Date)

    If Len(strMonth) = 1 Then
    strMonth = "0" & strMonth
    End If

    strDay = Day(Date)

    If Len(strDay) = 1 Then
    strDay = "0" & strDay
    End If

    strYear = Year(Date)

    strFolderName = "C:\Scripts\Tammy_" & strMonth & "-" & strDay & "-" & strYear

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.CreateFolder(strFolderName)

    How can I use or modify this script so that it creates a folder with yesterday's date?

  • #2
    Re: Creating Folders by Date

    I think the easiest way will be to use DateAdd function:
    Code:
    strMonth = Month(Date)
    
    If Len(strMonth) = 1 Then
    strMonth = "0" & strMonth
    End If
    
    strDay = Day(DateAdd("d", -1, Date))
    
    If Len(strDay) = 1 Then
    strDay = "0" & strDay
    End If
    
    strYear = Year(Date)
    
    strFolderName = "C:\Scripts\Tammy_" & strMonth & "-" & strDay & "-" & strYear
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.CreateFolder(strFolderName)

    Sorin Solomon


    In order to succeed, your desire for success should be greater than your fear of failure.
    -

    Comment


    • #3
      Re: Creating Folders by Date

      Sweet you are awesome. Thank you that works beautiful

      Comment


      • #4
        Re: Creating Folders by Date

        I'm glad to hear.
        Thank you for flying Petri's forumlines (sorry, the tough afternoon hours ).

        Sorin Solomon


        In order to succeed, your desire for success should be greater than your fear of failure.
        -

        Comment


        • #5
          Re: Creating Folders by Date

          Would that modification take into account if you're running it on the first of the month?
          ** Remember to give credit where credit is due and leave reputation points where appropriate **

          Comment


          • #6
            Re: Creating Folders by Date

            Yeap. According to VB Language Reference, it's a pretty clever function, that takes in consideration February's 28 days and leap years...

            Sorin Solomon


            In order to succeed, your desire for success should be greater than your fear of failure.
            -

            Comment

            Working...
            X