mistux Site Admin

Joined: 25 Jun 2004 Posts: 1042 Location: South Bend, Indiana USA
|
Posted: Wed Aug 20, 2014 10:40 am Post subject: Move files and folders |
|
|
Code: |
DIM PathToClean
DIM PathToArchive
DIM FSO
DIM objFolder
DIM ObjFile
' =====================
' set the variables
' =====================
PathToClean = "C:\Test"
PathToArchive = "C:\Test2" 'This must exist allready
set FSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = FSO.GetFolder(PathToClean)
For Each objFile in objFolder.Files
func_MoveFile objFile,PathToArchive
Next
func_GetSubFolders objFolder,PathToArchive
wscript.echo "All Done!!!"
set PathToClean = nothing
set PathToArchive = nothing
set FSO = nothing
set objFolder = nothing
set objFile = nothing
Function func_GetSubFolders(objFolder, strPath)
' -----------------------------------------------------------
'
' This function will recursively create subfolders
' in another location and it will call a function
' to move the older files
'
' -----------------------------------------------------------
DIM arrPath, i, strMyPath, strNewPath
DIM SubFolder, objFile
' ========================
' Create the New Path
' ========================
arrpath = split(objFolder.Path, "\")
If ubound(arrpath) > 1 then
For i = 2 to ubound(arrpath) '**This number might need to be increased to as many \ as you have in the first path
strMyPath = strMyPath + "\" & arrpath(i)
Next
strMyPath = strPath & "\" & strMyPath
Else
strMyPath = strpath
End If
' ========================
' resurse subfolders
' ========================
For Each SubFolder in objFolder.subFolders
strNewPath = strMyPath & "\" & subFolder.name
If FSO.FolderExists(strNewPath) = False then
FSO.CreateFolder strNewPath
End If
For Each objFile in subFolder.Files
Func_MoveFile objFile,strNewPath
Next
func_GetSubFolders subFolder,strPath
Next
End Function
vbscript that will scan a folder and all subfolders within that folder for files over 30 days old.
Source: http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23179311.html
Function func_MoveFile(objFile, strPath)
' -----------------------------------------------------------
'
' This function will copy any file that is older
' then 30 days to the strPath location
'
' -----------------------------------------------------------
If datediff("d", objFile.DateLastModified, Now()) > 30 then
FSO.MoveFile objFile.Path, strPath & "\"
End If
End Function
|
|
|