Simple File Organizer v1.04

This script grabs the date (modified or create date) from the file and
creates a folder based on the date in the following format (MM-DD-YY)
and moves the file into the newly created and designated folder. If
the folder exist then the file is simply moved. NOTE: If the files
have been copied from another pc be sure to uncomment line 53
(tFile.DateLastModified) to use the Modified date instead of the
(tFile.DateCreated), so comment out line 54 before running the script.
Because if the files have a common create date then all files will be
groupped into a single folder.

This script is ideal for unorganized photos still on a media card and
files unorganized in a folder such as downloaded items, but there are
many other uses I suppose.

Example:
Filename1 has a create date of Jan. 13, 2009 then this would be
grouped into a folder called 01-13-09.
Filename2 has a create date of Oct. 17, 2009 then this would be
grouped into a folder called 10-17-09.

VERIFIED ON:
This script has been tested against Windows 2003, XP & Vista.

NOTE: Rename the file from .txt to .vbs and edit line 42 to specify
the target folder before running. This only targets files in the
parent directory, files in sub-directories will not be affected.

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

Posted via email from wetmatter nonsense

0 comments: