3 Replies - 5249 Views - Last Post: 26 February 2010 - 12:52 AM

#1 theunborncoder   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 123
  • Joined: 15-October 09

Create folder with date name to store daily files

Posted 18 November 2009 - 01:56 AM

Description: require reference to "visual basic runtime objects and procedures"this code create folder named on date if missing so we can use this code to store daily updates like save application log file in daily new created folder
''call this function from any code to create folder name based on todays date
''We can use this code to store log files in daily created folder 

Public Sub fnCreateLogFolder()
Dim fs
'create reference for file system object 
    Set fs = CreateObject("Scripting.FileSystemObject")

'set basic folder path to D: we avoid c: because it may be contain system files        
        folderpath = "D:"

'check for D: if missing then go for C:
        If fs.DriveExists(folderpath) Then
            folderpath = "D:"
        Else
            folderpath = "C:"
        End If
    
'Check folder name "log" in folderpath
    If fs.FolderExists(folderpath & "Log") = True Then

        If fs.FolderExists(folderpath & "Log" & Replace(Format(Now(), "dd/MM/yyyy"), "/", "_")) = True Then
          Exit Sub
        Else
            fs.createfolder folderpath & "Log" & Replace(Format(Now(), "dd/MM/yyyy"), "/", "_")
        End If
        
    Else
'if log folder missing then create it
        fs.createfolder folderpath & "Log"
        fs.createfolder folderpath & "Log" & Replace(Format(Now(), "dd/MM/yyyy"), "/", "_")
    End If
    
End Sub




Is This A Good Question/Topic? 0
  • +

Replies To: Create folder with date name to store daily files

#2 Eliminator2009   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-February 10

Re: Create folder with date name to store daily files

Posted 19 February 2010 - 11:21 PM

Nice code but please declare folderpath variable. Thanks for the code
Was This Post Helpful? 0
  • +
  • -

#3 paulmurley   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 17-February 10

Re: Create folder with date name to store daily files

Posted 26 February 2010 - 12:47 AM

format(dd_mm_yyyy) works thus eliminating the replace(). Also if you change the dd_mm_yyyy to yyyy_mm_dd the folders will appear in correct ascending/descending order in file explorer etc.
Was This Post Helpful? 0
  • +
  • -

#4 paulmurley   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 17-February 10

Re: Create folder with date name to store daily files

Posted 26 February 2010 - 12:52 AM

Sorry - also forgot Add 'Microsoft Scripting Runtime' to Your Project>References and you can replace Dim fs 'create reference for file system object Set fs = CreateObject("Scripting.FileSystemObject") with Dim fso As New FileSystemObject
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1