# Solved: VBScript: Create Folders for each day within current month



## DMahany (Mar 2, 2011)

I'm attempting to create a backup system for my workplace (Win XP on all workstations). Currently, the plan is to have a backup folder subdivided into months, then days for that month.
example:
BACKUP
|-01
| |-01
| |-02
| |-03
|-02
| |-01
| |-02
| |-03

and so forth.

I've got a script to create the appropriate folder(s) on a per-day basis, but I'm stumped on how to automate it. I'm thinking of simply looping it for X number of days, but I don't know if that's the right way to go about it. Any help would be appreciated.

Here's what I've got so far.


```
'Defining and expanding Variables
Set fso = CreateObject("Scripting.FileSystemObject") 
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
 
'Create the Month Folder if it doesn't exist
strFolderName = "C:\BACKUP\" & strMonth
 if fso.FolderExists(strFolderName) then
 wscript.echo "Month Folder Exists: " & strMonth
 else
 Set objFolder = fso.CreateFolder(strFolderName) 
 end if
 
'Create the Day Folder if it doesn't exist
strFolderName = "C:\BACKUP\" & strMonth & "\" & strDay
 if fso.FolderExists(strFolderName) then
 wscript.echo "Day Folder Exists: " & strDay
 else
 Set objFolder = fso.CreateFolder(strFolderName) 
 end if
```


----------



## DMahany (Mar 2, 2011)

I've got it figured out. Running the script during any day of the month, will create the month folder, and all day folders within that month, in the format of C:\BACKUP\MM\DD


```
'Defining and expanding Variables
Set fso = CreateObject("Scripting.FileSystemObject")
strMonth = Month(Date)
 If Len(strMonth) = 1 Then
 strMonth = "0" & strMonth
 End If
strGetEndDay = DateSerial(Year(Now), 1 + Month(Now), 0)
strEndDay = Day(strGetEndDay)
 If Len(strEndDay) = 1 Then
 strEndDay = "0" & strEndDay
 End If
'Create the Month Folder if it exists
strFolderName = "C:\BACKUP\" & strMonth
 if fso.FolderExists(strFolderName) then
 wscript.echo "Month Folder Exists: " & strMonth
 else
 Set objFolder = fso.CreateFolder(strFolderName)
 end if
'Create the Day Folder if it exists
For strMakeDay = 1 To strEndDay
 if Len(strMakeDay) = 1 Then
 strMakeDay = "0" & strMakeDay
 End If
strFolderName = "C:\BACKUP\" & strMonth & "\" & strMakeDay
 if fso.FolderExists(strFolderName) then
 wscript.echo "Day Folder Exists: " & strMakeDay
 else
 Set objFolder = fso.CreateFolder(strFolderName)
 end if
Next
```


----------

