Login | |
|
 |
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.
|
|
| |
|
|
|
 |
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.
|
|
| |
|
|
|
 |
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.
|
|
| |
|
|
|
 |
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.
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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.
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
|
|