Manufacturing Information Solutions Forum Index Manufacturing Information Solutions
Your Place for Support and Discussions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Move files and folders

Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> VB Script
View previous topic :: View next topic  
Author Message
Site Admin

Joined: 25 Jun 2004
Posts: 1042
Location: South Bend, Indiana USA

PostPosted: Wed Aug 20, 2014 10:40 am    Post subject: Move files and folders Reply with quote


DIM PathToClean
DIM PathToArchive
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
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)
                strMyPath = strPath & "\" & strMyPath
                strMyPath = strpath
        End If
        ' ========================
        '   resurse subfolders
        ' ========================
   For Each SubFolder in objFolder.subFolders
      strNewPath = strMyPath & "\" &
      If FSO.FolderExists(strNewPath) = False then
         FSO.CreateFolder strNewPath
      End If
      For Each objFile in subFolder.Files
                        Func_MoveFile objFile,strNewPath
      func_GetSubFolders subFolder,strPath                     
End Function
 vbscript that will scan a folder and all subfolders within that folder for files over 30 days old.

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
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> VB Script All times are GMT - 5 Hours
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group