Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thank you for the best reply I've ever had to a forum question - it's extremely comprehensive and legible and answers my query thoroughly..."

Geography

Where in the world do Tek-Tips members come from?

Moving files based on DateLastModified

Onenguyen (TechnicalUser)
29 Jul 12 13:59
thread329-1666328: Script to extract directory names by modified date

I just want to say that I love this forum and I have learned so much from just browsing.

I have a script that I am using from a previous thread and I need some assistance with modifying it to suit my needs.

1) I need the script to move instead of copy. When I change the objFolder.Copy to objFolder.Move the error file says it was unable to move folder. Is this because of Permissions?

2) I am attempting to run this script on a VERY big set of folders (Close to 2TB). I had it running overnight and nothing had been accomplished. Is this because it has to find the documents before it starts copying, thus making it very time consuming? Is there anyway to clean up or modify the script so it doesn't take so long? I tried it on a smaller subset (60gb) and it still takes a long time for it to start.

CODE --> VBScript

const ForAppending = 8
set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("WScript.Shell")
set objTextFile = objFSO.OpenTextFile ("L:\env4\LOG.log", ForAppending, True)

function findRecentFile(strDir, strRecent)  
    dim objFolder  
    set objFolder = objFSO.GetFolder(strDir)
    for each objSubFolder in objFolder.SubFolders
        strRecent = findRecentFile(objSubFolder.Path, strRecent)
        'strLog = strLog & findRecentFile(objSubFolder.Path, intAge)
    next

    for each objFile in objFolder.Files
        if (strRecent = "") then
             strRecent = objFile.Path
        else
            if (objFile.DateLastModified > objFSO.GetFile(strRecent).DateLastModified) then strRecent = objFile.Path
        end if
    next
    findRecentFile = strRecent
end function

intAge = 90 '3 months
strSource = "L:\env4\12025_0009"
strDestination = "D:\12025_0009\"

'strLog = findRecentFile(strSource, intAge)

'Header = "Folder | Last Date Modified | Last Date Accessed"
'objTextFile.WriteLine(Header)
'objTextFile.WriteLine(strLog)
'objTextFile.Close

for each objFolder in objFSO.GetFolder(strSource).SubFolders
    strFile = findRecentFile(objFolder.Path, "")
    if (strFile <> "") then
        strModDate = objFSO.GetFile(strFile).DateLastModified
        strProjectFolder = objFSO.GetParentFolderName(strFile)
    else
        strModDate = objFolder.DateLastModified
        strProjectFolder = objFolder.Name
    end if
    if (datediff("d", strModDate, now) > intAge) then
    	On Error Resume Next
    	Err.Clear
        objFolder.Copy strDestination & objFolder.Name
        If Err.Number <> 0 Then
        	objTextFile.WriteLine(objFolder.Path & vbTab & "Folder was not transferred")
        else
        	objTextFile.WriteLine(objFolder.Path & vbTab & "Folder successfully transferred")
        
        end if
	 	  
       end if     
    
next 

Thank you!
Onenguyen (TechnicalUser)
29 Jul 12 14:03
One more quick questions. Is there a way to make it so that if the folder doesn't exist, it creates it automatically?

CODE -->

strDestination = "D:\12025_0009\" 

I want it to be able to create the top level parent folder.

Thanks!!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close