Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


need help with exclusion

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> need help with exclusion
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 need help with exclusion - 12/16/2005 9:32:05 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
here is my script which will delete everything past 30 days recursive.
can anyone show me how to add an exclusion to a specific file name?
i want this not to delete a file called "bla.pen" & "save.doc" but everything should be deleted after 30 days.

Option Explicit
on error resume next
Dim fso, ddates
ddates = Date() - 4
Set fso = CreateObject("Scripting.FileSystemObject")
DirWalk("C:\Documents and Settings\tom\Desktop\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 oFile.DateLastModified < ddates Then
fso.DeleteFile oFile.Path, True
End If
Next
For Each oSubDir In oSubFolder.Subfolders
DirWalk oSubDir.Path      
Next
On Error Goto 0             
End Sub
 
 
Post #: 1
 
 RE: need help with exclusion - 12/16/2005 9:44:58 AM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
Wrap it in an IF statment...


If filename = ?????  then
   Do nothing
else  
   Do stuff
end if

Cybex

_____________________________

Common sense is not so common.

(in reply to kracksmith)
 
 
Post #: 2
 
 RE: need help with exclusion - 12/16/2005 9:52:46 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
well i don't want this script find the specific file and quit.

i want it to find the file and continue


so i would image it would be like this:


if file exist then continuing delete everything pass 30 days except for this file or that file. or if this file doesn't exist still continue to delete everything else.


I don't think your scripture above will adapt to this.

plus where do I insert this statement once I figure it out?

< Message edited by kracksmith -- 12/16/2005 10:02:13 AM >

(in reply to Cybex)
 
 
Post #: 3
 
 RE: need help with exclusion - 12/16/2005 12:17:23 PM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
What is wrong with this...

Option Explicit
On Error Resume Next
Dim fso, ddates
ddates = Date() - 4
Set fso = CreateObject("Scripting.FileSystemObject")
DirWalk("C:\scripts\deltest")

Sub DirWalk(parmPath)
Dim oSubDir, oSubFolder, oFile, n
'On Error Resume Next        
Set oSubFolder = fso.getfolder(parmPath)
For Each oFile In oSubFolder.Files
   If oFile.DateLastModified < ddates Then
       If ofile.name <> "save.doc" Then
           If ofile.name <> "bla.pen" Then

               fso.DeleteFile oFile.Path, True
           End If
       End If

   End If
Next
For Each oSubDir In oSubFolder.Subfolders
   DirWalk oSubDir.Path     
Next
On Error Goto 0            
End Sub

It seems to do what you asked for in my tests.

Cybex

EDIT***

I will keep trying to figure a way to include them in one line I just haven't been able to focus on the syxtax for that due to work.

< Message edited by Cybex -- 12/16/2005 1:02:32 PM >


_____________________________

Common sense is not so common.

(in reply to kracksmith)
 
 
Post #: 4
 
 RE: need help with exclusion - 12/16/2005 1:27:01 PM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
Ok this will work for the two file names.  If you have more I would look at putting them into an array and looping thru them for exclusion.

Option Explicit
On Error Resume Next
Dim fso, ddates
ddates = Date() - 4
Set fso = CreateObject("Scripting.FileSystemObject")
DirWalk("C:\scripts\deltest")

Sub DirWalk(parmPath)
Dim oSubDir, oSubFolder, oFile, n
'On Error Resume Next        
Set oSubFolder = fso.getfolder(parmPath)
For Each oFile In oSubFolder.Files
   If oFile.DateLastModified < ddates Then
       If ofile.name <> "save.doc" And ofile.name <> "bla.pen" Then
               fso.DeleteFile oFile.Path, True
       End If
   End If
Next
For Each oSubDir In oSubFolder.Subfolders
   DirWalk oSubDir.Path     
Next
On Error Goto 0            
End Sub

Cybex

_____________________________

Common sense is not so common.

(in reply to Cybex)
 
 
Post #: 5
 
 RE: need help with exclusion - 12/19/2005 8:12:44 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
hey thanks, the 1st one actually did the trick.

hmmm, i don't know how to sneak this in but  how would i incorporate multiple paths with this script?

would it be hard to do?


(in reply to Cybex)
 
 
Post #: 6
 
 RE: need help with exclusion - 12/19/2005 8:21:35 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Just create an array of the paths (or read them one at a time from a text file) then do the meat of the script for each path.

_____________________________

"... 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 kracksmith)
 
 
Post #: 7
 
 RE: need help with exclusion - 12/20/2005 12:04:18 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
quote:

ORIGINAL: Cybex

SNIP
      If ofile.name <> "save.doc" And ofile.name <> "bla.pen" Then
              fso.DeleteFile oFile.Path, True
      End If
Snip
Cybex


Wouldn't it be better to use OR instead of AND?  I hate this somethings, OR and AND that is,  but to me it seems that OR would be better suited here.  Because if the file name is save.doc it would not be bla.pen so it would not be true and the deletion would happen.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to Cybex)
 
 
Post #: 8
 
 RE: need help with exclusion - 12/20/2005 1:19:05 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Oh come now. Ands and Ors are what seperate us from the lower life forms.

_____________________________

"... 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 mbouchard)
 
 
Post #: 9
 
 RE: need help with exclusion - 12/20/2005 2:30:56 AM   
  DiGiTAL.SkReAM


Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Why not use select case?

Select Case UCase(ofile.name)
case "save.doc"
   'Do nothing
case "bla.pen"
   'Do nothing
case else
   fso.DeleteFile oFile.Path, True
End Select

I have always been under the impression that select case statements process a little quicker than if...then statements.  And it also gives the added benefit of being able to add more filenames super-easily in the future... just add another case "filename" line - no arrays required.

_____________________________

"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 ebgreen)
 
 
Post #: 10
 
 RE: need help with exclusion - 12/20/2005 2:35:48 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
But then you have to edit code to essentially change data. Keeping the file names and paths in a seprerate data source eliminates the possible induction of errors into otherwise functional code. Not a big deal for a small script. Very big deal if this would be running against hundreds of files/paths.

_____________________________

"... 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 DiGiTAL.SkReAM)
 
 
Post #: 11
 
 RE: need help with exclusion - 12/20/2005 2:49:50 AM   
  DiGiTAL.SkReAM


Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
I agree in part.

In the case that the filenames that are excluded never change, or might change once a year, it doesn't make sense to increment the complexity of the script by adding code to open a text file, read each line into a string, running checks against the string to ensure that the data is correctly formatted, assign that string to an array element, close the file, and then go into iterating through the array elements.

If the filenames changed often or there were a large number of exclusions, I would say that it would be worth it to go to the additional effort required to go the array-from-file way.  But if the filenames are relatively static and there wouldn't be more than 5 or 6 of them, I would suggest sticking with the select case method.

I don't see where the number of files/filepaths that the script is run against has anything to do with it.


_____________________________

"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 ebgreen)
 
 
Post #: 12
 
 RE: need help with exclusion - 12/20/2005 2:56:08 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
quote:

I don't see where the number of files/filepaths that the script is run against has anything to do with it.


Because this was the question:
quote:

hmmm, i don't know how to sneak this in but  how would i incorporate multiple paths with this script


_____________________________

"... 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 DiGiTAL.SkReAM)
 
 
Post #: 13
 
 RE: need help with exclusion - 12/20/2005 4:14:24 AM   
  DiGiTAL.SkReAM


Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
quote:

ORIGINAL: ebgreen

quote:

I don't see where the number of files/filepaths that the script is run against has anything to do with it.


Because this was the question:
quote:

hmmm, i don't know how to sneak this in but  how would i incorporate multiple paths with this script



Oh, I see what is going on. 
I was suggesting using the select case statement to handle the filenames to exclude, and I thought that you were saying that he should use an external file to list the filenames to exclude.
Then, yes, if the user does not want to utilize fso. to get his paths, a text file read into an array is the way to go.

But I still say that a select case statement for the filenames to exclude from deletion is the best bet as far as that goes, rather than an IF...THEN.

_____________________________

"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 ebgreen)
 
 
Post #: 14
 
 RE: need help with exclusion - 12/20/2005 4:18:43 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
There is nothing wrong with the Select and it is better suited to the filenames portion than If-Thens. If it were me however, I would use a dictionary for the file information. Then there would be more flexibility availabe. For instance it would be trivial to set up logic to delete file type A if it was over 30 days old but only delete file type B if it was over 45 days old. Again it is a matter of scale. For a small scale application a simple Select Case would be fine, but if the application wants to be scalable, then a flexible data structure like a dictionary is the way to go. Simply my opinion though.

_____________________________

"... 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 DiGiTAL.SkReAM)
 
 
Post #: 15
 
 RE: need help with exclusion - 12/20/2005 6:07:43 AM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
Good debate and all good points but Kracksmith asked about two specifically named files…
 
Or is this an example of over-engineering at work?


Cybex

_____________________________

Common sense is not so common.

(in reply to ebgreen)
 
 
Post #: 16
 
 RE: need help with exclusion - 12/20/2005 9:06:42 AM   
  DiGiTAL.SkReAM


Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
quote:

ORIGINAL: Cybex

Good debate and all good points but Kracksmith asked about two specifically named files…

Or is this an example of over-engineering at work?


Cybex


I do have a tendency to build a clock to find out what time it is.

_____________________________

"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 Cybex)
 
 
Post #: 17
 
 RE: need help with exclusion - 12/20/2005 10:17:16 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
YES! good debate

The little I know about programming is that CASE statements are used when there are a lot of options

OR & AND statements are ok for very few options like in my situation.

just throwing in my 2 cents worth of 411.

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 18
 
 RE: need help with exclusion - 12/21/2005 2:58:59 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
I tend to overengineer as well. In my defense however it is the result of being asked to tell the user the time then later being asked to tell them the time in every timezone and in the language that is predominant in that timezone. I assume 3 things:
1) Whatever I am being asked to do is the tip of the iceberg and will need to be expanded at some point.
2) Making a script as flexible as possible does add some up front time but not as much as rewriting to accomodate new needs.
3) Someone else will be maintaining the script so make it as logically clear and easy to follow as possible (not to mention comments).

That last one is arguably the most important one and the one I have the hardest time following through on.

_____________________________

"... 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 kracksmith)
 
 
Post #: 19
 
 RE: need help with exclusion - 12/21/2005 7:42:04 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Here is my over engineered version. It needs a text file named Paths.txt in the same directory. This file would have the paths to search in it one per line. It also can have a file named Exclusions.txt in the same directory. If this file is there then any files that should be excluded need to be listed one per line. This means that to have another path searched, you just need to add one line to a text file. The same is true if you want to add one more file to exclude. Just add a line to the text file.

      

I haven't tested it but it should work barring some silly syntaxt error on my part.

_____________________________

"... 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 ebgreen)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

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 >> need help with exclusion Page: [1] 2   next >   >>
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