Script Center > Gallery > Storage > Simple File Organizer v1.04
TechNet Script Center logo

Welcome to the TechNet Script Center Gallery!

Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.

Simple File Organizer v1.04

(Community)
Rate it:
 
 
 
 
 
Script Code
VBScript
Option Explicit
'=============================================================================
'Script:        SimpleFileOrganizer_1.04.vbs
'Purpose:       Automates file to folder organization
'Author:        sqlsamson (SJL)
'Version:       v1.04 (2009.10.22)
'
'Description:
'		This script grabs the create date from the file 
'		and creates a folder based on the modified date MM-DD-YY
'		and moves the file to the newly created and designated 
'		folder if the folder exist then the file is moved.
'
'		If the files have been copied from another pc besure to
'		un-comment line 53 (tFile.DateLastModified) to use the Modified
'		date instead and comment out line 54 before running the script.
'
'		Because if the files have a common create date then all will
'		be groupped into a single folder.
'
'		Great for unorganized photos still on media card and files
'		unorganized in a folder like downloaded items.
'
'Variables:
'		============================================
'		Edit strFolderPath to desired target folder
'		============================================
'
'Usage:		
'		Double click SimpleFileOrganizer_1.04.vbs to execute or
'		from a command prompt cscript SimpleFileOrganizer_1.04.vbs.
'		Confirmation is presented at the very end of the process.
'=============================================================================

' ========== Header ========== 
Dim objFSO,dTimer,strFolderPath,targetFolder,targetFiles,file,tFile
Dim newFolderName,folderDate, intCnt, strMsg
Set objFSO = CreateObject("Scripting.FileSystemObject")

' ========== Reference ========== 
dTimer			= Now()
strFolderPath 		= "G:\My_VBS\testFiles\"
intCnt			= 0

' ========== Process ========== 
If objFSO.FolderExists(strFolderPath) Then
	Set targetFolder 	= objFSO.GetFolder(strFolderPath)
	Set targetFiles 	= targetFolder.Files
	
		For each file in targetFiles
			
			Set tFile		= objFSO.GetFile(targetFolder & "\" & file.name)
			'folderDate		= tFile.DateLastModified
			folderDate		= tFile.DateCreated 
			newFolderName		= Right("0" & Month(folderDate),2) & "-" & Right("0" & Day(folderDate),2) & "-" & Right("0" & Year(folderDate),2)
				
				If objFSO.FolderExists(targetFolder & "\"  & newFolderName) Then
					objFSO.MoveFile targetFolder & "\" & file.name, targetFolder & "\" & newFolderName & "\" & file.name
				ElSE
					objFSO.CreateFolder(targetFolder & "\" & newFolderName)
					objFSO.MoveFile targetFolder & "\" & file.name, targetFolder & "\" & newFolderName  & "\" & file.name
				END IF
			intCnt = intCnt + 1
		Next

Else
	strMsg = MsgBox("Path not found: (" & strFolderPath & ") Terminating process.",16,"Invalid Path Error")
	WScript.Quit(9)
End If

' ========== Output ========== 
WScript.Echo "The process took " & DateDiff("s",dTimer,Now()) & " seconds to organize (" & intCnt & ") file(s)!"


' ========== Clean Up ========== 
Set objFSO 		= Nothing
Set TargetFolder 	= Nothing
Set targetFiles 	= Nothing
Set tFile		= Nothing
intCnt			= ""
dTimer			= NULL
WScript.Quit
Platforms
Windows Server 2008 R2 No
Windows Server 2008 No
Windows Server 2003 Yes
Windows 7 No
Windows Vista Yes
Windows XP Yes
Windows 2000 No
For online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.