Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Archiving files

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Archiving files
  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 >>
 Archiving files - 10/9/2006 7:52:49 PM   
  Tiernobyl

 

Posts: 6
Score: 0
Joined: 10/9/2006
Status: offline
I'm trying to automate archiving of files on one of our servers.  A colleague has been doing this manually for a while and now, with new regulations in place, he is no longer able to write to the directory where the archives are stored.  He thought this would be a perfect opportunity to automate the process. 

When the number of files in the directory goes above 95, a new folder is created and these files are moved to this folder.  The folder name is "Archive " then the current date.  The code below generates an error when run on the server - line 31, char 5, bad file name or number.  Can somebody please have a look and find out what I'm doing wrong.  I'm fairly new to vbs and this is the first script i've written.


      
 
 
Post #: 1
 
 RE: Archiving files - 10/9/2006 8:56:42 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
quote:

fso.CreateFolder




the above line must be set before the For-loop or else it errors saying it already exists...with that said...if in the root folder 98 files exists the archiving is done over all of those 98, not just 95, so setting up a delimeter is also a must, to retain the 95-files limit

I like the way you log in the EventVwr, but that is local-loggin...wouldn't you prefer more a server-side logging (eg. txt file on the server) to monitor events remotely?

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to Tiernobyl)
 
 
Post #: 2
 
 RE: Archiving files - 10/9/2006 9:08:06 PM   
  Tiernobyl

 

Posts: 6
Score: 0
Joined: 10/9/2006
Status: offline
Could you give me some advice on how and where to add the delimeter?

Unfortunately that would create a new folder everyday, and not only when the number of files exceeds 95.  The idea was to run this as a schelduled task everyday on this particular server.  Although we do use NetIQ to monitor the network; currently an event is raised when the number of files in the folder goes above the 95-files limit, and an email sent out to the guy who was doing this manually before.  I don't know if you can help me with this, but do you know any way that this script could run as soon as the event is raised? 



< Message edited by Tiernobyl -- 10/9/2006 9:17:55 PM >

(in reply to Snipah)
 
 
Post #: 3
 
 RE: Archiving files - 10/9/2006 10:41:46 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
quote:

currently an event is raised when the number of files in the folder goes above the 95-files limit [...]  do you know any way that this script could run as soon as the event is raised


you'll need to know the event is raised, where to read it from (we use NetIQ for DRA, so personally no experience with the monitoring)

To create the folder when the files exceed 95 can be done with an If statement and FolderExists..does it also occur that the files exceed their limit multiple times a day?

Add a delimiter (one of the so many ways):

i=0
For Each File In Files
[...]
If datediff("d",File.DateLastModified,Now) > 1 And FileCount > 95 AND i < 96 Then
   'Move files
   File.Move """" & path & "\" & archpath & "\" & File.Name & """"
End If
[...]
 i=i+1
Next

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to Tiernobyl)
 
 
Post #: 4
 
 RE: Archiving files - 10/9/2006 11:53:33 PM   
  Tiernobyl

 

Posts: 6
Score: 0
Joined: 10/9/2006
Status: offline
Thank you very much

I can run a batch file when the event is raised in NetIQ, so I can have this pointing to the vbs.  That means the folder will only be created when the event is raised.

(in reply to Snipah)
 
 
Post #: 5
 
 RE: Archiving files - 10/10/2006 12:09:45 AM   
  Tiernobyl

 

Posts: 6
Score: 0
Joined: 10/9/2006
Status: offline
I don't understand!!!   The file started ok, created the folder, moved two of the files....  and then it caused another bad file name or number error!!!  on the same line again: fso.CreateFolder  line 25 char 2

Why did this happen?  Have I not closed one of the If's or something?  Please help


      

(in reply to Tiernobyl)
 
 
Post #: 6
 
 RE: Archiving files - 10/10/2006 12:41:08 AM   
  DiGiTAL.SkReAM


Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Well, it is possible that one of the files is locked by being open/in use.  Just checking the modified time won't guarantee that it isn't opened.
Also, it might help a bit if the entire script were pasted.  For example, it would help explain was gets passed into the path, archpath, and filetype arguments.

Do you want to move the files if there are exactly 95 files or only if there are 96 or more files?

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to Tiernobyl)
 
 
Post #: 7
 
 RE: Archiving files - 10/10/2006 12:53:25 AM   
  Tiernobyl

 

Posts: 6
Score: 0
Joined: 10/9/2006
Status: offline
Sorry, here it is, there's not much else though.  I'm going to run the file when the even is raised in NetIQ to say that there are more than 95 files.  It doesn't really matter how many more than 95 files there are, so I have removed the delimiter as I do not believe it is required.  The error is occuring on this line: fso.CreateFolder """" & path & "\" & archpath & """"

The files are definetely not in use as this is a test directory on a test server.  A new file is created when the older file is not in use, so just checking the modified date should be sufficient for this task.


      

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 8
 
 RE: Archiving files - 10/10/2006 1:46:17 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
I was trying to run your script and had the same errors Snipah suggested removing the """" from fso.CreateFolder  path & "\" & archpath
and it worked.
The other problem you will have is you will need to see if the folder exsists if not create a new folder + 1 each time else once again the script will fail as the folder already exsists.

(in reply to Tiernobyl)
 
 
Post #: 9
 
 RE: Archiving files - 10/10/2006 2:03:16 AM   
  Tiernobyl

 

Posts: 6
Score: 0
Joined: 10/9/2006
Status: offline
The files do not increase in number to worry about that.  Perhaps a new file is created every one or sometimes even two days, so it will take a good couple months before a new folder is created.

Thanks so much guys 

(in reply to gdewrance)
 
 
Post #: 10
 
 
 
  

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 >> Archiving files 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