|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Script to echo files based on specific dates
I am pretty new to scripting. I found this script from "scripting guy" and I want to know how I can echo or even delete files within a specific folder (for example D:\folder1\subfolder2\test) for files older than Jan 2nd 2007. I thought it would work if I change the line " AND Drive = 'D:\folder1\subfolder2\test'"). But this doesn't work. I would appreciate any help! Thanks, WG strDate = "20070102000000.000000+000" strComputer = "." Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colFiles = objWMIService.ExecQuery _ ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _ " AND Drive = 'D:'") For Each objFile in colFiles Wscript.Echo objFile.Name Next AND Drive='D:' AND Path='\\folder1\\subfolder2\\test\\'
Show quote "Walid" wrote: > Hi, > I am pretty new to scripting. I found this script from "scripting guy" and > I want to know how I can echo or even delete files within a specific folder > (for example D:\folder1\subfolder2\test) for files older than Jan 2nd 2007. > I thought it would work if I change the line " AND Drive = > 'D:\folder1\subfolder2\test'"). But this doesn't work. I would appreciate > any help! > > Thanks, > > WG > > strDate = "20070102000000.000000+000" > > strComputer = "." > Set objWMIService = GetObject _ > ("winmgmts:\\" & strComputer & "\root\cimv2") > Set colFiles = objWMIService.ExecQuery _ > ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _ > " AND Drive = 'D:'") > For Each objFile in colFiles > Wscript.Echo objFile.Name > Next > > That worked; thank-you very much!!
How would I modify this script if I want to echo based on "modified" date, file size, file type (.doc, .pdf, .... etc)? Thanks for the assistance! WG Show quote "JFord" wrote: > AND Drive='D:' AND Path='\\folder1\\subfolder2\\test\\' > > "Walid" wrote: > > > Hi, > > I am pretty new to scripting. I found this script from "scripting guy" and > > I want to know how I can echo or even delete files within a specific folder > > (for example D:\folder1\subfolder2\test) for files older than Jan 2nd 2007. > > I thought it would work if I change the line " AND Drive = > > 'D:\folder1\subfolder2\test'"). But this doesn't work. I would appreciate > > any help! > > > > Thanks, > > > > WG > > > > strDate = "20070102000000.000000+000" > > > > strComputer = "." > > Set objWMIService = GetObject _ > > ("winmgmts:\\" & strComputer & "\root\cimv2") > > Set colFiles = objWMIService.ExecQuery _ > > ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _ > > " AND Drive = 'D:'") > > For Each objFile in colFiles > > Wscript.Echo objFile.Name > > Next > > > > Here is a free tool called ScriptoMatic it will help you with your WMI queries
http://www.microsoft.com/downloads/details.aspx?familyid=09dfc342-648b-4119-b7eb-783b0f7d1178&displaylang=en
There are a lot of properties you can query off of - LastModified - FileType - Extension - FileSize You will see these in the ScriptoMatic tool, or just google the WMI Class name http://msdn2.microsoft.com/en-us/library/aa387236.aspx Also as 'tonyr' suggests sometimes vbscript can create a mental block, powershell is pretty good and there are a few examples out there for it as well. Show quote "Walid" wrote: > That worked; thank-you very much!! > How would I modify this script if I want to echo based on "modified" date, > file size, file type (.doc, .pdf, .... etc)? > > Thanks for the assistance! > > WG > > "JFord" wrote: > > > AND Drive='D:' AND Path='\\folder1\\subfolder2\\test\\' > > > > "Walid" wrote: > > > > > Hi, > > > I am pretty new to scripting. I found this script from "scripting guy" and > > > I want to know how I can echo or even delete files within a specific folder > > > (for example D:\folder1\subfolder2\test) for files older than Jan 2nd 2007. > > > I thought it would work if I change the line " AND Drive = > > > 'D:\folder1\subfolder2\test'"). But this doesn't work. I would appreciate > > > any help! > > > > > > Thanks, > > > > > > WG > > > > > > strDate = "20070102000000.000000+000" > > > > > > strComputer = "." > > > Set objWMIService = GetObject _ > > > ("winmgmts:\\" & strComputer & "\root\cimv2") > > > Set colFiles = objWMIService.ExecQuery _ > > > ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _ > > > " AND Drive = 'D:'") > > > For Each objFile in colFiles > > > Wscript.Echo objFile.Name > > > Next > > > > > > also if your new to scripting I'd make the switch to powershell, you
shouldn't have all the mental barriers us vbs guys have! my .00000000001 cents worth the equivelant I think would be ls d:\somedir -rec | foreach {$_.creationtime -lt "01/02/2007"} if its a remote device then ls \\servername\d$\somedir -rec | foreach {$_.creationtime -lt "01/02/2007"} Show quote "Walid" wrote: > Hi, > I am pretty new to scripting. I found this script from "scripting guy" and > I want to know how I can echo or even delete files within a specific folder > (for example D:\folder1\subfolder2\test) for files older than Jan 2nd 2007. > I thought it would work if I change the line " AND Drive = > 'D:\folder1\subfolder2\test'"). But this doesn't work. I would appreciate > any help! > > Thanks, > > WG > > strDate = "20070102000000.000000+000" > > strComputer = "." > Set objWMIService = GetObject _ > ("winmgmts:\\" & strComputer & "\root\cimv2") > Set colFiles = objWMIService.ExecQuery _ > ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _ > " AND Drive = 'D:'") > For Each objFile in colFiles > Wscript.Echo objFile.Name > Next > > Thanks for the tip. Is powershell different than VBScripting? I am running
WinXP Pro on my workstation so I believe I have to install it on my machine, correct? Also, does the remote server that I query by the poweshell command need to have it installed? As you can see I need some direction :-) Any help regarding this would be much appreciated. "ls" would echo. What would be the delete command in powershell? W Show quote "tonyr" wrote: > also if your new to scripting I'd make the switch to powershell, you > shouldn't have all the mental barriers us vbs guys have! > my .00000000001 cents worth > > the equivelant I think would be > > ls d:\somedir -rec | foreach {$_.creationtime -lt "01/02/2007"} > > if its a remote device then > > ls \\servername\d$\somedir -rec | foreach {$_.creationtime -lt "01/02/2007"} > > > > "Walid" wrote: > > > Hi, > > I am pretty new to scripting. I found this script from "scripting guy" and > > I want to know how I can echo or even delete files within a specific folder > > (for example D:\folder1\subfolder2\test) for files older than Jan 2nd 2007. > > I thought it would work if I change the line " AND Drive = > > 'D:\folder1\subfolder2\test'"). But this doesn't work. I would appreciate > > any help! > > > > Thanks, > > > > WG > > > > strDate = "20070102000000.000000+000" > > > > strComputer = "." > > Set objWMIService = GetObject _ > > ("winmgmts:\\" & strComputer & "\root\cimv2") > > Set colFiles = objWMIService.ExecQuery _ > > ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _ > > " AND Drive = 'D:'") > > For Each objFile in colFiles > > Wscript.Echo objFile.Name > > Next > > > > yes you need to install it and no the remote server\workstation does not need
it installed! as a starter I'd go here http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx Show quote "Walid" wrote: > Thanks for the tip. Is powershell different than VBScripting? I am running > WinXP Pro on my workstation so I believe I have to install it on my machine, > correct? Also, does the remote server that I query by the poweshell command > need to have it installed? As you can see I need some direction :-) Any help > regarding this would be much appreciated. > > "ls" would echo. What would be the delete command in powershell? > > W > > "tonyr" wrote: > > > also if your new to scripting I'd make the switch to powershell, you > > shouldn't have all the mental barriers us vbs guys have! > > my .00000000001 cents worth > > > > the equivelant I think would be > > > > ls d:\somedir -rec | foreach {$_.creationtime -lt "01/02/2007"} > > > > if its a remote device then > > > > ls \\servername\d$\somedir -rec | foreach {$_.creationtime -lt "01/02/2007"} > > > > > > > > "Walid" wrote: > > > > > Hi, > > > I am pretty new to scripting. I found this script from "scripting guy" and > > > I want to know how I can echo or even delete files within a specific folder > > > (for example D:\folder1\subfolder2\test) for files older than Jan 2nd 2007. > > > I thought it would work if I change the line " AND Drive = > > > 'D:\folder1\subfolder2\test'"). But this doesn't work. I would appreciate > > > any help! > > > > > > Thanks, > > > > > > WG > > > > > > strDate = "20070102000000.000000+000" > > > > > > strComputer = "." > > > Set objWMIService = GetObject _ > > > ("winmgmts:\\" & strComputer & "\root\cimv2") > > > Set colFiles = objWMIService.ExecQuery _ > > > ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _ > > > " AND Drive = 'D:'") > > > For Each objFile in colFiles > > > Wscript.Echo objFile.Name > > > Next > > > > > > Thank-you all! This has been very helpful!
Show quote "tonyr" wrote: > yes you need to install it and no the remote server\workstation does not need > it installed! > > as a starter I'd go here > > http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx > > > > "Walid" wrote: > > > Thanks for the tip. Is powershell different than VBScripting? I am running > > WinXP Pro on my workstation so I believe I have to install it on my machine, > > correct? Also, does the remote server that I query by the poweshell command > > need to have it installed? As you can see I need some direction :-) Any help > > regarding this would be much appreciated. > > > > "ls" would echo. What would be the delete command in powershell? > > > > W > > > > "tonyr" wrote: > > > > > also if your new to scripting I'd make the switch to powershell, you > > > shouldn't have all the mental barriers us vbs guys have! > > > my .00000000001 cents worth > > > > > > the equivelant I think would be > > > > > > ls d:\somedir -rec | foreach {$_.creationtime -lt "01/02/2007"} > > > > > > if its a remote device then > > > > > > ls \\servername\d$\somedir -rec | foreach {$_.creationtime -lt "01/02/2007"} > > > > > > > > > > > > "Walid" wrote: > > > > > > > Hi, > > > > I am pretty new to scripting. I found this script from "scripting guy" and > > > > I want to know how I can echo or even delete files within a specific folder > > > > (for example D:\folder1\subfolder2\test) for files older than Jan 2nd 2007. > > > > I thought it would work if I change the line " AND Drive = > > > > 'D:\folder1\subfolder2\test'"). But this doesn't work. I would appreciate > > > > any help! > > > > > > > > Thanks, > > > > > > > > WG > > > > > > > > strDate = "20070102000000.000000+000" > > > > > > > > strComputer = "." > > > > Set objWMIService = GetObject _ > > > > ("winmgmts:\\" & strComputer & "\root\cimv2") > > > > Set colFiles = objWMIService.ExecQuery _ > > > > ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _ > > > > " AND Drive = 'D:'") > > > > For Each objFile in colFiles > > > > Wscript.Echo objFile.Name > > > > Next > > > > > > > > |
|||||||||||||||||||||||