![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Did I do this right I tried to put together some Pegasus stuff together he did, but did I do this right? I don't think my nested If's work right or if thats the best way to do what i'm trying to do. Sub CheckFolder (oFldr) If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then For Each oFile In oFldr.Files Checked = Checked + 1 If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then If instr(1, oFile.Name, "@", 1) > 0 Then Deleted = Deleted + 1 'WScript.Echo verb & oFile.Path & """" If Active Then oFile.Delete End If End If Next End If if not Recursive then Exit Sub For Each oSubfolder In oFldr.Subfolders CheckFolder(oSubfolder) Next End Sub |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Did I do this right Rich wrote: Quote: >I tried to put together some Pegasus stuff together he did, but did I do >this > right? I don't think my nested If's work right or if thats the best way > to > do what i'm trying to do. > > Sub CheckFolder (oFldr) > If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then > For Each oFile In oFldr.Files > Checked = Checked + 1 > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then > If instr(1, oFile.Name, "@", 1) > 0 Then > Deleted = Deleted + 1 > 'WScript.Echo verb & oFile.Path & """" > If Active Then oFile.Delete > End If > End If > Next > End If > > if not Recursive then Exit Sub > For Each oSubfolder In oFldr.Subfolders > CheckFolder(oSubfolder) > Next > End Sub executable code outside of methods. They are not subroutines or functions in themselves, although they can define them within. This version worked for me, where I encapsulated the executable code in a Sub. Note I had to call the Sub to have the public properties assigned values: =============== class current_date public month public day public year Public Sub GetDate strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime") For Each objItem in colItems month = objItem.Month day = objItem.Day year = objItem.Year Next End Sub end class '********************** dim test set test = new current_date test.GetDate wscript.echo test.month wscript.echo test.day wscript.echo test.year -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Did I do this right Rich wrote: Quote: >I tried to put together some Pegasus stuff together he did, but did I do >this > right? I don't think my nested If's work right or if thats the best way > to > do what i'm trying to do. > > Sub CheckFolder (oFldr) > If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then > For Each oFile In oFldr.Files > Checked = Checked + 1 > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then > If instr(1, oFile.Name, "@", 1) > 0 Then > Deleted = Deleted + 1 > 'WScript.Echo verb & oFile.Path & """" > If Active Then oFile.Delete > End If > End If > Next > End If > > if not Recursive then Exit Sub > For Each oSubfolder In oFldr.Subfolders > CheckFolder(oSubfolder) > Next > End Sub thread, and I somehow got confused. In regard to your code above, I can only say I find no syntax errors. I like to indent If/Then/End If and For Each/Next structures for clarity. My version of your code follows: ======== Sub CheckFolder (oFldr) If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then For Each oFile In oFldr.Files Checked = Checked + 1 If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then If instr(1, oFile.Name, "@", 1) > 0 Then Deleted = Deleted + 1 'WScript.Echo verb & oFile.Path & """" If Active Then oFile.Delete End If End If End If Next End If if not Recursive then Exit Sub End If For Each oSubfolder In oFldr.Subfolders CheckFolder(oSubfolder) Next End Sub ====== My other comment is that the Sub depends on global variables defined elsewhere: sFolderNames, Recursive, Active, MaxAge. It might be better to make them parameters passed to the Sub (or assigned values in the Sub). And I don't know what Checked and Deleted are for, as they are not used. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Did I do this right Thanks Richard. I wasn't sure if all those nested if's would actually do what I wanted to or not, as it appeared not to delete the files in question. "Richard Mueller [MVP]" wrote: Quote: > Rich wrote: > Quote: > >I tried to put together some Pegasus stuff together he did, but did I do > >this > > right? I don't think my nested If's work right or if thats the best way > > to > > do what i'm trying to do. > > > > Sub CheckFolder (oFldr) > > If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then > > For Each oFile In oFldr.Files > > Checked = Checked + 1 > > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then > > If instr(1, oFile.Name, "@", 1) > 0 Then > > Deleted = Deleted + 1 > > 'WScript.Echo verb & oFile.Path & """" > > If Active Then oFile.Delete > > End If > > End If > > Next > > End If > > > > if not Recursive then Exit Sub > > For Each oSubfolder In oFldr.Subfolders > > CheckFolder(oSubfolder) > > Next > > End Sub > Sorry, ignore my previous reply in this thread. It was meant for another > thread, and I somehow got confused. > > In regard to your code above, I can only say I find no syntax errors. I like > to indent If/Then/End If and For Each/Next structures for clarity. My > version of your code follows: > ======== > Sub CheckFolder (oFldr) > If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then > For Each oFile In oFldr.Files > Checked = Checked + 1 > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then > If instr(1, oFile.Name, "@", 1) > 0 Then > Deleted = Deleted + 1 > 'WScript.Echo verb & oFile.Path & """" > If Active Then > oFile.Delete > End If > End If > End If > Next > End If > > if not Recursive then > Exit Sub > End If > For Each oSubfolder In oFldr.Subfolders > CheckFolder(oSubfolder) > Next > End Sub > ====== > My other comment is that the Sub depends on global variables defined > elsewhere: sFolderNames, Recursive, Active, MaxAge. It might be better to > make them parameters passed to the Sub (or assigned values in the Sub). And > I don't know what Checked and Deleted are for, as they are not used. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Did I do this right It's pretty hard to determine whether or not the sub will do what you want it to do when all we have to go on is the code (I can only assume that your intention was for the code to do what the code does), and when we do not know what value SFolderNames might have (amongst others). I would suggest that writing a sub that is dependent on the calling routine having setup certain variables in advance is often a recipe for failure. I would also suggest that this is doubly true for a recursive sub. /Al "Rich" <richjone@xxxxxx> wrote in message news:E18B8462-A73A-47DE-9341-6EC899A1A477@xxxxxx Quote: > Thanks Richard. I wasn't sure if all those nested if's would actually do > what I wanted to or not, as it appeared not to delete the files in > question. > > "Richard Mueller [MVP]" wrote: > Quote: >> Rich wrote: >> Quote: >> >I tried to put together some Pegasus stuff together he did, but did I do >> >this >> > right? I don't think my nested If's work right or if thats the best >> > way >> > to >> > do what i'm trying to do. >> > >> > Sub CheckFolder (oFldr) >> > If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then >> > For Each oFile In oFldr.Files >> > Checked = Checked + 1 >> > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then >> > If instr(1, oFile.Name, "@", 1) > 0 Then >> > Deleted = Deleted + 1 >> > 'WScript.Echo verb & oFile.Path & """" >> > If Active Then oFile.Delete >> > End If >> > End If >> > Next >> > End If >> > >> > if not Recursive then Exit Sub >> > For Each oSubfolder In oFldr.Subfolders >> > CheckFolder(oSubfolder) >> > Next >> > End Sub >> Sorry, ignore my previous reply in this thread. It was meant for another >> thread, and I somehow got confused. >> >> In regard to your code above, I can only say I find no syntax errors. I >> like >> to indent If/Then/End If and For Each/Next structures for clarity. My >> version of your code follows: >> ======== >> Sub CheckFolder (oFldr) >> If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then >> For Each oFile In oFldr.Files >> Checked = Checked + 1 >> If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then >> If instr(1, oFile.Name, "@", 1) > 0 Then >> Deleted = Deleted + 1 >> 'WScript.Echo verb & oFile.Path & """" >> If Active Then >> oFile.Delete >> End If >> End If >> End If >> Next >> End If >> >> if not Recursive then >> Exit Sub >> End If >> For Each oSubfolder In oFldr.Subfolders >> CheckFolder(oSubfolder) >> Next >> End Sub >> ====== >> My other comment is that the Sub depends on global variables defined >> elsewhere: sFolderNames, Recursive, Active, MaxAge. It might be better to >> make them parameters passed to the Sub (or assigned values in the Sub). >> And >> I don't know what Checked and Deleted are for, as they are not used. >> >> -- >> Richard Mueller >> MVP Directory Services >> Hilltop Lab - http://www.rlmueller.net >> -- >> >> >> |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Did I do this right Hello again Al. You had actually helped with that code originally haha. I probably didn't ask my question right. I guess I wanted to know that if all the criteria for those couple if statements were met would it actually delete the file. I'm always leery with if after if's, but it looks like it is working. Sorry for the confusion. "Al Dunbar" wrote: Quote: > It's pretty hard to determine whether or not the sub will do what you want > it to do when all we have to go on is the code (I can only assume that your > intention was for the code to do what the code does), and when we do not > know what value SFolderNames might have (amongst others). > > I would suggest that writing a sub that is dependent on the calling routine > having setup certain variables in advance is often a recipe for failure. I > would also suggest that this is doubly true for a recursive sub. > > > /Al > > > "Rich" <richjone@xxxxxx> wrote in message > news:E18B8462-A73A-47DE-9341-6EC899A1A477@xxxxxx Quote: > > Thanks Richard. I wasn't sure if all those nested if's would actually do > > what I wanted to or not, as it appeared not to delete the files in > > question. > > > > "Richard Mueller [MVP]" wrote: > > Quote: > >> Rich wrote: > >> > >> >I tried to put together some Pegasus stuff together he did, but did I do > >> >this > >> > right? I don't think my nested If's work right or if thats the best > >> > way > >> > to > >> > do what i'm trying to do. > >> > > >> > Sub CheckFolder (oFldr) > >> > If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then > >> > For Each oFile In oFldr.Files > >> > Checked = Checked + 1 > >> > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then > >> > If instr(1, oFile.Name, "@", 1) > 0 Then > >> > Deleted = Deleted + 1 > >> > 'WScript.Echo verb & oFile.Path & """" > >> > If Active Then oFile.Delete > >> > End If > >> > End If > >> > Next > >> > End If > >> > > >> > if not Recursive then Exit Sub > >> > For Each oSubfolder In oFldr.Subfolders > >> > CheckFolder(oSubfolder) > >> > Next > >> > End Sub > >> > >> Sorry, ignore my previous reply in this thread. It was meant for another > >> thread, and I somehow got confused. > >> > >> In regard to your code above, I can only say I find no syntax errors. I > >> like > >> to indent If/Then/End If and For Each/Next structures for clarity. My > >> version of your code follows: > >> ======== > >> Sub CheckFolder (oFldr) > >> If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then > >> For Each oFile In oFldr.Files > >> Checked = Checked + 1 > >> If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then > >> If instr(1, oFile.Name, "@", 1) > 0 Then > >> Deleted = Deleted + 1 > >> 'WScript.Echo verb & oFile.Path & """" > >> If Active Then > >> oFile.Delete > >> End If > >> End If > >> End If > >> Next > >> End If > >> > >> if not Recursive then > >> Exit Sub > >> End If > >> For Each oSubfolder In oFldr.Subfolders > >> CheckFolder(oSubfolder) > >> Next > >> End Sub > >> ====== > >> My other comment is that the Sub depends on global variables defined > >> elsewhere: sFolderNames, Recursive, Active, MaxAge. It might be better to > >> make them parameters passed to the Sub (or assigned values in the Sub). > >> And > >> I don't know what Checked and Deleted are for, as they are not used. > >> > >> -- > >> Richard Mueller > >> MVP Directory Services > >> Hilltop Lab - http://www.rlmueller.net > >> -- > >> > >> > >> > > > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Did I do this right "Rich" <richjone@xxxxxx> wrote in message news:98D63E80-7347-4379-BEB1-63FC359CB893@xxxxxx Quote: > Hello again Al. You had actually helped with that code originally haha. > > I probably didn't ask my question right. I guess I wanted to know that if > all the criteria for those couple if statements were met would it actually > delete the file. I'm always leery with if after if's, but it looks like > it > is working. Sorry for the confusion. debug if it doesn't) than to look at it and wonder. Have you tried it? /Al Quote: > "Al Dunbar" wrote: > Quote: >> It's pretty hard to determine whether or not the sub will do what you >> want >> it to do when all we have to go on is the code (I can only assume that >> your >> intention was for the code to do what the code does), and when we do not >> know what value SFolderNames might have (amongst others). >> >> I would suggest that writing a sub that is dependent on the calling >> routine >> having setup certain variables in advance is often a recipe for failure. >> I >> would also suggest that this is doubly true for a recursive sub. >> >> >> /Al >> >> >> "Rich" <richjone@xxxxxx> wrote in message >> news:E18B8462-A73A-47DE-9341-6EC899A1A477@xxxxxx Quote: >> > Thanks Richard. I wasn't sure if all those nested if's would actually >> > do >> > what I wanted to or not, as it appeared not to delete the files in >> > question. >> > >> > "Richard Mueller [MVP]" wrote: >> > >> >> Rich wrote: >> >> >> >> >I tried to put together some Pegasus stuff together he did, but did I >> >> >do >> >> >this >> >> > right? I don't think my nested If's work right or if thats the best >> >> > way >> >> > to >> >> > do what i'm trying to do. >> >> > >> >> > Sub CheckFolder (oFldr) >> >> > If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then >> >> > For Each oFile In oFldr.Files >> >> > Checked = Checked + 1 >> >> > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then >> >> > If instr(1, oFile.Name, "@", 1) > 0 Then >> >> > Deleted = Deleted + 1 >> >> > 'WScript.Echo verb & oFile.Path & """" >> >> > If Active Then oFile.Delete >> >> > End If >> >> > End If >> >> > Next >> >> > End If >> >> > >> >> > if not Recursive then Exit Sub >> >> > For Each oSubfolder In oFldr.Subfolders >> >> > CheckFolder(oSubfolder) >> >> > Next >> >> > End Sub >> >> >> >> Sorry, ignore my previous reply in this thread. It was meant for >> >> another >> >> thread, and I somehow got confused. >> >> >> >> In regard to your code above, I can only say I find no syntax errors. >> >> I >> >> like >> >> to indent If/Then/End If and For Each/Next structures for clarity. My >> >> version of your code follows: >> >> ======== >> >> Sub CheckFolder (oFldr) >> >> If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then >> >> For Each oFile In oFldr.Files >> >> Checked = Checked + 1 >> >> If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge >> >> Then >> >> If instr(1, oFile.Name, "@", 1) > 0 Then >> >> Deleted = Deleted + 1 >> >> 'WScript.Echo verb & oFile.Path & """" >> >> If Active Then >> >> oFile.Delete >> >> End If >> >> End If >> >> End If >> >> Next >> >> End If >> >> >> >> if not Recursive then >> >> Exit Sub >> >> End If >> >> For Each oSubfolder In oFldr.Subfolders >> >> CheckFolder(oSubfolder) >> >> Next >> >> End Sub >> >> ====== >> >> My other comment is that the Sub depends on global variables defined >> >> elsewhere: sFolderNames, Recursive, Active, MaxAge. It might be better >> >> to >> >> make them parameters passed to the Sub (or assigned values in the >> >> Sub). >> >> And >> >> I don't know what Checked and Deleted are for, as they are not used. >> >> >> >> -- >> >> Richard Mueller >> >> MVP Directory Services >> >> Hilltop Lab - http://www.rlmueller.net >> >> -- >> >> >> >> >> >> >> >> >> |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Did I do this right Yeah, I did try it, and it appeared not to work. But then I realized a flaw in the info given to me that I was comparing it to after all these subsequent posts. I do appreciate the help. "Al Dunbar" wrote: Quote: > > "Rich" <richjone@xxxxxx> wrote in message > news:98D63E80-7347-4379-BEB1-63FC359CB893@xxxxxx Quote: > > Hello again Al. You had actually helped with that code originally haha. > > > > I probably didn't ask my question right. I guess I wanted to know that if > > all the criteria for those couple if statements were met would it actually > > delete the file. I'm always leery with if after if's, but it looks like > > it > > is working. Sorry for the confusion. > I find that it is less work to actually try the code to see if it works (and > debug if it doesn't) than to look at it and wonder. Have you tried it? > > /Al > Quote: > > "Al Dunbar" wrote: > > Quote: > >> It's pretty hard to determine whether or not the sub will do what you > >> want > >> it to do when all we have to go on is the code (I can only assume that > >> your > >> intention was for the code to do what the code does), and when we do not > >> know what value SFolderNames might have (amongst others). > >> > >> I would suggest that writing a sub that is dependent on the calling > >> routine > >> having setup certain variables in advance is often a recipe for failure. > >> I > >> would also suggest that this is doubly true for a recursive sub. > >> > >> > >> /Al > >> > >> > >> "Rich" <richjone@xxxxxx> wrote in message > >> news:E18B8462-A73A-47DE-9341-6EC899A1A477@xxxxxx > >> > Thanks Richard. I wasn't sure if all those nested if's would actually > >> > do > >> > what I wanted to or not, as it appeared not to delete the files in > >> > question. > >> > > >> > "Richard Mueller [MVP]" wrote: > >> > > >> >> Rich wrote: > >> >> > >> >> >I tried to put together some Pegasus stuff together he did, but did I > >> >> >do > >> >> >this > >> >> > right? I don't think my nested If's work right or if thats the best > >> >> > way > >> >> > to > >> >> > do what i'm trying to do. > >> >> > > >> >> > Sub CheckFolder (oFldr) > >> >> > If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then > >> >> > For Each oFile In oFldr.Files > >> >> > Checked = Checked + 1 > >> >> > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then > >> >> > If instr(1, oFile.Name, "@", 1) > 0 Then > >> >> > Deleted = Deleted + 1 > >> >> > 'WScript.Echo verb & oFile.Path & """" > >> >> > If Active Then oFile.Delete > >> >> > End If > >> >> > End If > >> >> > Next > >> >> > End If > >> >> > > >> >> > if not Recursive then Exit Sub > >> >> > For Each oSubfolder In oFldr.Subfolders > >> >> > CheckFolder(oSubfolder) > >> >> > Next > >> >> > End Sub > >> >> > >> >> Sorry, ignore my previous reply in this thread. It was meant for > >> >> another > >> >> thread, and I somehow got confused. > >> >> > >> >> In regard to your code above, I can only say I find no syntax errors. > >> >> I > >> >> like > >> >> to indent If/Then/End If and For Each/Next structures for clarity. My > >> >> version of your code follows: > >> >> ======== > >> >> Sub CheckFolder (oFldr) > >> >> If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then > >> >> For Each oFile In oFldr.Files > >> >> Checked = Checked + 1 > >> >> If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge > >> >> Then > >> >> If instr(1, oFile.Name, "@", 1) > 0 Then > >> >> Deleted = Deleted + 1 > >> >> 'WScript.Echo verb & oFile.Path & """" > >> >> If Active Then > >> >> oFile.Delete > >> >> End If > >> >> End If > >> >> End If > >> >> Next > >> >> End If > >> >> > >> >> if not Recursive then > >> >> Exit Sub > >> >> End If > >> >> For Each oSubfolder In oFldr.Subfolders > >> >> CheckFolder(oSubfolder) > >> >> Next > >> >> End Sub > >> >> ====== > >> >> My other comment is that the Sub depends on global variables defined > >> >> elsewhere: sFolderNames, Recursive, Active, MaxAge. It might be better > >> >> to > >> >> make them parameters passed to the Sub (or assigned values in the > >> >> Sub). > >> >> And > >> >> I don't know what Checked and Deleted are for, as they are not used. > >> >> > >> >> -- > >> >> Richard Mueller > >> >> MVP Directory Services > >> >> Hilltop Lab - http://www.rlmueller.net > >> >> -- > >> >> > >> >> > >> >> > >> > >> > >> > >> > > > |
My System Specs![]() |