Here you go. You'll have to modify the date function still.
[
copy or print]
'*********************************************************
' Sorter.vbs
'
' 3:30 PM 11/04/2008
'
' A. Timperley aka SirSmiley
'
' Purpose:
'
Sort Files Into Date Specific Folders. Creates folders if none exist.
'
Non-Recursive. Eg. Doesn't do subfolders
' Inputs:
'
Dropped Folders
' Returns:
'
Msgbox notification on completion
'*********************************************************
Dim objArgs : Set objArgs = WScript.Arguments
' Declore array's
Dim arrDropItems()
' all dropped items
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
' Set the path to your target folder here
Dim objTargetFldr ': objTargetFldr = "C:\Programming\Sandbox\x"
' Special character
' Use double quotes with no space if you wish to have a straight date
Dim sSC : sSC = "."
' Configure Sorting Method
' 1 = Date Created | 2 = Date Last Accessed | 3 = Date Last Modified
Dim iSortDate : iSortDate = 3
'Splits dropped folders into an array
' You can drop multiple folders this way
For I = 0 to objArgs.Count - 1
If I <0 Then
WScript.Quit
Else
' Build Array from Dropped Items
ReDim Preserve arrDropItems(I)
arrDropItems(I)=objArgs(I)
End If
Next
Call ArraySort
' Sort Array
Function ArraySort
For i=0 To UBound(arrDropItems)
' Determines if dropped item is a folder or file
If objFSO.FolderExists(objArgs(i)) Then
Call SortFolders(objArgs(I))
ElseIf objFSO.FileExists(objArgs(i)) Then
Call SortFiles(objArgs(I))
End If
Next
End Function
' Checks to see if Target Date Folder Exists
' Creates one if none exists
Function DateFolder(strDate)
' Format Date
strSortDate = DatePart("yyyy",strDate)&sSC
If DatePart("m",strDate) < 10 Then
strSortDate = strSortDate & "0"
End If
strSortDate = strSortDate & DatePart("m",strDate)&sSC
If DatePart("d",strDate) < 10 Then
strSortDate = strSortDate & "0"
End If
strSortDate = strSortDate & DatePart("d",strDate)
strTargetFldr = objTargetFldr&"\"&strSortDate
If objFSO.FolderExists(strTargetFldr) Then
DateFolder=strTargetFldr&"\"
Else'If objFSO.FolderExists(strTargetFldr)=False Then
objFSO.CreateFolder(strTargetFldr)
DateFolder=strTargetFldr&"\"
End IF
End Function
' Creates File Collection from Folders in Array. Sorts Accordingly
Sub SortFolders(strFolder)
Set objFolder = objFSO.GetFolder(strFolder)
objTargetFldr = objFolder'
' Get's File Collection
Set objFileCol=objFolder.Files
For Each File In objFileCol
If iSortDate = 1 Then
strTargetFldr = DateFolder(File.DateCreated)
objFSO.MoveFile File,strTargetFldr
ElseIf iSortDate = 2 Then
strTargetFldr= DateFolder(File.DateLastAccessed)
objFSO.MoveFile File,strTargetFldr
ElseIf iSortDate = 3 Then
strTargetFldr= DateFolder(File.DateLastModified)
objFSO.MoveFile File,strTargetFldr
End If
Next
msgbox "Folder Contents Sorting Complete"
End Sub
' Sort's Files to Date Formated Folders
Sub SortFiles(strFile)
Set strFile=objFSO.GetFile(strFile)
strFolder=objFSO.GetParentFolderName(strFile)
strFolder=objFSO.GetAbsolutePathName(strFolder)
Set objFolder = objFSO.GetFolder(strFolder)
objTargetFldr = objFolder
If iSortDate = 1 Then
strTargetFldr = DateFolder(strFile.DateCreated)
objFSO.MoveFile strFile,strTargetFldr
ElseIf iSortDate = 2 Then
strTargetFldr= DateFolder(strFile.DateLastAccessed)
objFSO.MoveFile strFile,strTargetFldr
ElseIf iSortDate = 3 Then
strTargetFldr= DateFolder(strFile.DateLastModified)
objFSO.MoveFile strFile,strTargetFldr
End If
msgbox "Files Sorting Complete"
End Sub