'***********************************
' FUNCTIONS AND SUBS
'***********************************
sub createDirectory (strDir)
set objFSO = CreateObject("Scripting.FileSystemObject")
if (right(strDir, 1) = "\") then strDir = left(strDir, len(strDir) - 1)
strParentDir = objFSO.GetParentFolderName(strDir)
if NOT (objFSO.FolderExists(strParentDir)) then createDirectory (strParentDir)
if NOT (objFSO.FolderExists(strDir)) then objFSO.CreateFolder (strDir)
end sub
function searchFolder(strDir, strExt, boolSubFolders)
set objFSO = CreateObject("Scripting.FileSystemObject")
if (objFSO.FolderExists(strDir)) then
set objFolder = objFSO.GetFolder(strDir)
strExt = lcase(strExt)
if (boolSubFolders) then
for each objSubFolder in objFolder.SubFolder
strResults = searchForOrder (objSubFolder.Path, strCriteria)
next
end if
for each objFile in objFolder.Files
if (right(objFile.Name, len(strExt)) = strExt) then strResults = strResults & objFile.Path & vbNewLine
next
searchFolder = split(strResults, vbNewLine)
end if
end function
sub moveFiles(arrFiles, strDestination)
set objFSO = CreateObject("Scripting.FileSystemObject")
for each strFile in arrFiles
if (strFile <> "") then
set objFile = objFSO.GetFile(strFile)
objFSO.MoveFile strFile, strDestination & "\" & objFile.Name
end if
next
end sub
'***********************************
' BEGIN
'***********************************
dim arrPaths(2)
arrPaths(0) = "C:\temp\images"
arrPaths(1) = "C:\documents and settings\user\photos"
arrPaths(2) = "D:\development\pictures"
strExt = ".jpg"
strDestination = "D:\Images"
for each strPath in arrPaths
arrFiles = searchFolder(strPath, strExt, false)
createDirectory strDestination
moveFiles arrFiles, strDestination
next