Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Moving files by date- PLEASE HELP

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,34345
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Moving files by date- PLEASE HELP
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Moving files by date- PLEASE HELP - 5/10/2006 8:30:59 AM   
  mwill

 

Posts: 5
Score: 0
Joined: 5/10/2006
Status: offline
Hello all,

I new to this site but it looks amazing! I was wondering if one could help me with a problem I have. A scirpting problem.

Heres what I want to acomplish.

I want a VBScript that will work on a windows 2003 server that will do the following:

Search through a directory and its subdirectories (about 20 folders and many files) and find all the files within the folders that have been modified from its orginal date, and move these files to another server as a backup.

So if File A in Folder A has a date of 03/04/2006 and tomorrow the file modifed date is 05/02/2006 it will move only this file to a folder I have on another server.

I'm very confused on where to start on this!!!

Another part I want to try is this:

Search through a folder and its files within the folder and move only files that are older than 7 days and move this to another folder on a different server as a backup!

Again i'm not a guru on VBS i can write simple scripts, but this is over whelming me. I would appericate any advice or help somone can lean me!

Thanks Guys your all the best!

 
 
Post #: 1
 
 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.

(in reply to mwill)
 
 
Post #: 2
 
 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.

(in reply to mbouchard)
 
 
Post #: 3
 
 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.

(in reply to mwill)
 
 
Post #: 4
 
 RE: Moving files by date- PLEASE HELP - 5/11/2006 5:58:49 AM   
  mwill

 

Posts: 5
Score: 0
Joined: 5/10/2006
Status: offline
Thanks for the reply again mbouchard. However i'm unable to get that to work in my script. Heres what happens.

If I try it as follows:

Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("\\Tk-421\public_docs\Recruiting\")
Set fc = f.Files
For Each f1 in fc
DestLocation = replace(f1.path,"\\Tk-421\","\\AA-23\")
WScript.Echo destlocation'Will contain the new path, only replacing
the server name.
Next



It echos back the same path where it was from TK-421. The replace is not changing the server path for me. I've tried changing it around serveral times with no luck.


**This is an edit. Please ignore the above. I found the problem. I noticed when it echoed back it was case sensitive. So by changing an upper to a lower it actually worked.. Doh.

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?!

The bigger question however, is just to get the sample you provided above to work first.

Thanks for any advice!

< Message edited by mwill -- 5/11/2006 6:08:09 AM >

(in reply to mbouchard)
 
 
Post #: 5
 
 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.

(in reply to mwill)
 
 
Post #: 6
 
 RE: Moving files by date- PLEASE HELP - 5/12/2006 12:54:43 AM   
  mwill

 

Posts: 5
Score: 0
Joined: 5/10/2006
Status: offline
Hi mbouchard and all,

My problem just evolved into a different issue. "sigh" The team wants me to go about this a different way. Maybe you or a fellow forum member can help?

Heres what they are wanting me to do now.

ServerA has a directory with lots of subdirectories.

-Root
-FolderA
File A
  -FolderB
  FileB
  FileB
    -FolderC
   FileC
   FileC 

SeverB is a duplicate copy of all these file and folders.

-Root
-FolderA
File A
  -FolderB
  FileB
  FileB
    -FolderC
   FileC
   FileC 


They are now wanting me to make a backup of all changed files by comparing these agasint each other. Then move the changed files or new files into the same folder from which it came from into the exact duplicate files and folders from the other server.

-So a script that will list all files and folders on the main server, then check to see if a file has been changed, if it has then copy only this file over to the new server back into the same folder onto the backup server.


I have a script that does this much. It list the directoires of both folders and checks the date modifed and path. But i'm unable to make it disgunish between the two different folders, and make it move the files over! ugh. heres what I have now. Any advice you can suggest?


Set fso = CreateObject("Scripting.FileSystemObject")
DirWalk("c:\test\")
DirWalk("c:\test2\")
Sub DirWalk(parmPath)
Dim oSubDir, oSubFolder, oFile, n
  On Error Resume Next       
  Set oSubFolder = fso.getfolder(parmPath)
  For Each oFile In oSubFolder.Files 
  
   DateMod = oFile.path & oFile.DateLastModified
      Wscript.echo DateMod        
  Next
  For Each oSubDir In oSubFolder.Subfolders
     DirWalk oSubDir.Path      ' recurse the DirWalk sub with the subdir paths
  Next

End Sub


With just this bit i'm able to recurse both folder, and get the path and date modified from each folder. How can I use this to check against each other? And if its different tell it to copy the file from c:\test to c:\test2 back into the backup server?

I might be going about this an incorrect way. IF you think so what would you do?

Thanks again for all you do.

(in reply to mbouchard)
 
 
Post #: 7
 
 RE: Moving files by date- PLEASE HELP - 5/12/2006 2:17:24 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Your team wants you to reinvent the wheel. Use RoboCopy. It is designed specifically for tasks such as this.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mwill)
 
 
Post #: 8
 
 RE: Moving files by date- PLEASE HELP - 5/12/2006 5:22:02 AM   
  mwill

 

Posts: 5
Score: 0
Joined: 5/10/2006
Status: offline
LoL,

Right before i seen this post. I noticed in the resource ket. Robocopy. And i've already made a batch file with only 5 lines of code to do the same thing i've tried with VBSCRIPT.

Man, talking about live and learn!

Thanks for all your help guys!

(in reply to ebgreen)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Moving files by date- PLEASE HELP Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts