Login | |
|
 |
RE: Moving files by date- PLEASE HELP - 5/10/2006 10:55:36 PM
|
|
 |
|
| |
mbouchard
Posts: 1922
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Almost everything here has been posted on this site at sometime or another. do a quick search on reiterate folders, or subfolders and you will find info on the first part. Then do a search on date and you should find the answer on the second part. My recommendation is write the script in several parts, which will make it easier to write. Script 1 Part1 - reiterate through a folder. Once you have that expand it to... Part2 - Reiterate through a folder and it's subfolders... Script 2 Part1 - work on getting the date from all files in a folder. Once you have that, expand it to.... Part2 - comparing dates based on your criteria. This should give you a start, if you get stuck any place in writing the scripts, post here. Many posters are glad to help others with issues, not with writing the whole script. As a whole, what you are doing can seem to be complex, but if you break it up into parts you should be able to get it working fairly easily. Hope this helps.
_____________________________
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|
| |
|
|
|
 |
RE: Moving files by date- PLEASE HELP - 5/11/2006 3:21:06 AM
|
|
 |
|
| |
mwill
Posts: 5
Score: 0
Joined: 5/10/2006
Status: offline
|
Thanks mbouchard, Searching for that key term actually helped alot. It got me halfway there. Heres the script I have now and heres the last part i'm stuck on. -I actually needed another script that will copy files from one folder to another whose date modified has been > 7 days. After getting some sample code that was easy. -Hard part for this script is: Now that I have this script to copy files over whose date modified has been 30 minutes, now i need it to copy these FILES over to the same exact folders they came out of to another duplicate server we have setup. -This dir has many subfolders and files within it. These files need to be put back in to the same folder from which it came from on the other server. So were making an exact backup, but only moving files whose been modifed within a 30 min period. Hope that makes sense. Can any one help me regarding this? I've tried to do a search again regarding this and wasnt lucky enough to find any information. Option Explicit Dim fso, d30minsago d30minsago = DateAdd("n", -30, Now()) Set fso = CreateObject("Scripting.FileSystemObject") DirWalk("c:\test\") Sub DirWalk(parmPath) Dim oSubDir, oSubFolder, oFile, n On Error Resume Next Set oSubFolder = fso.getfolder(parmPath) For Each oFile In oSubFolder.Files If Err.Number <> 0 Then Err.Clear ElseIf oFile.DateLastModified < d30minsago Then fso.copyfile oFile.Path, "c:\test2\" End If Next For Each oSubDir In oSubFolder.Subfolders DirWalk oSubDir.Path Next On Error Goto 0 End Sub This script copies all the modifed files from their folders into a single folder. I dont want that.. I want what i explained above. Any suggestions or advice where to start with this? Thanks in advance.
|
|
| |
|
|
|
 |
RE: Moving files by date- PLEASE HELP - 5/11/2006 3:35:26 AM
|
|
 |
|
| |
mbouchard
Posts: 1922
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
quote:
-This dir has many subfolders and files within it. These files need to be put back in to the same folder from which it came from on the other server. So were making an exact backup, but only moving files whose been modifed within a 30 min period. One possible way would be to use replace. For instance. Dim fso, f, f1, fc, s Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder("\\Server1\Someshare\somefolder1") Set fc = f.Files For Each f1 in fc DestLocation = replace(f1.path,"\Server1\","\server2\") WScript.Echo destlocation'Will contain the new path, only replacing the server name. Next
_____________________________
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|
| |
|
|
|
 |
RE: Moving files by date- PLEASE HELP - 5/11/2006 6:45:44 AM
|
|
 |
|
| |
mbouchard
Posts: 1922
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Sorry, normally in my scripts I "force" a case. I.e. DestLocation = replace(lcase(f1.path),"\\tk-421\","\\aa-23\") quote:
Also how would one implement this to copy the files into the same folders from which it came? This part i'm still working on however, any advice on this?! Something like this fso.copyfile f1.path,destlocation,true 'True = overwrite if already exists. You may want to put in some error checking.
_____________________________
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|
| |
|
|
|
|
|