![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | VBS SCRIPT to clean OLD FILE Hi all, I have a folder with same backup file and I must delete the file older than 4 days before. How can I do with VBS Script? thanks in advance |
My System Specs![]() |
| | #2 (permalink) |
| | Re: VBS SCRIPT to clean OLD FILE "AleP" <a@xxxxxx> wrote in message news:ga7vpi$8sf$1@xxxxxx Quote: > Hi all, > I have a folder with same backup file and I must delete the file older > than 4 days before. > How can I do with VBS Script? > thanks in advance > - Where does the drive/folder/file name come from? Is it fixed? User input? - When you say "older than 4 days before", do you mean "more than 4 days older than the original file" or "more than 4 days old, measured from today"? |
My System Specs![]() |
| | #3 (permalink) |
| | Re: VBS SCRIPT to clean OLD FILE Nel suo scritto precedente, Pegasus (MVP) ha sostenuto : Quote: > "AleP" <a@xxxxxx> wrote in message news:ga7vpi$8sf$1@xxxxxx Quote: >> Hi all, >> I have a folder with same backup file and I must delete the file older than >> 4 days before. >> How can I do with VBS Script? >> thanks in advance >> > You need to specify your requirements more precisely: > - Where does the drive/folder/file name come from? Is it fixed? User input? > - When you say "older than 4 days before", do you mean "more than 4 days > older than the original file" or "more than 4 days old, measured from today"? The directory is fixed and the file name is 5 different more than 3days from today thanks a lot |
My System Specs![]() |
| | #4 (permalink) |
| | Re: VBS SCRIPT to clean OLD FILE "AleP" <a@xxxxxx> wrote in message news:ga84hi$r6q$1@xxxxxx Quote: > Nel suo scritto precedente, Pegasus (MVP) ha sostenuto : Quote: >> "AleP" <a@xxxxxx> wrote in message news:ga7vpi$8sf$1@xxxxxx Quote: >>> Hi all, >>> I have a folder with same backup file and I must delete the file older >>> than 4 days before. >>> How can I do with VBS Script? >>> thanks in advance >>> >> You need to specify your requirements more precisely: >> - Where does the drive/folder/file name come from? Is it fixed? User >> input? >> - When you say "older than 4 days before", do you mean "more than 4 days >> older than the original file" or "more than 4 days old, measured from >> today"? > Hi. > The directory is fixed and the file name is 5 different > more than 3days from today > thanks a lot > > sFolder = "d:\temp\" sFile = "abc.txt" set iMaxAge = 5 Set oFSO = CreateObject("Scripting.FileSystemObject") If oFSO.FileExists(sFolder & sFile) Then Set oFile = oFSO.GetFile(sFolder & sFile) If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then WScript.Echo "oFile.Delete" End If End If When you're happy with the result, change this line WScript.Echo "oFile.Delete" to this one: oFile.Delete in order to activate the script. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: VBS SCRIPT to clean OLD FILE Scriveva Pegasus (MVP) mercoledì, 10/09/2008: Quote: > "AleP" <a@xxxxxx> wrote in message news:ga84hi$r6q$1@xxxxxx Quote: >> Nel suo scritto precedente, Pegasus (MVP) ha sostenuto : Quote: >>> "AleP" <a@xxxxxx> wrote in message news:ga7vpi$8sf$1@xxxxxx >>>> Hi all, >>>> I have a folder with same backup file and I must delete the file older >>>> than 4 days before. >>>> How can I do with VBS Script? >>>> thanks in advance >>>> >>> >>> You need to specify your requirements more precisely: >>> - Where does the drive/folder/file name come from? Is it fixed? User >>> input? >>> - When you say "older than 4 days before", do you mean "more than 4 days >>> older than the original file" or "more than 4 days old, measured from >>> today"? >> Hi. >> The directory is fixed and the file name is 5 different >> more than 3days from today >> thanks a lot >> >> > Try this: > sFolder = "d:\temp\" > sFile = "abc.txt" > set iMaxAge = 5 > Set oFSO = CreateObject("Scripting.FileSystemObject") > If oFSO.FileExists(sFolder & sFile) Then > Set oFile = oFSO.GetFile(sFolder & sFile) > If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then > WScript.Echo "oFile.Delete" > End If > End If > > When you're happy with the result, change this line > WScript.Echo "oFile.Delete" to this one: > oFile.Delete > in order to activate the script. |
My System Specs![]() |
| | #6 (permalink) |
| | Re: VBS SCRIPT to clean OLD FILE Dopo dura riflessione, AleP ha scritto : Quote: > Scriveva Pegasus (MVP) mercoledì, 10/09/2008: Quote: >> "AleP" <a@xxxxxx> wrote in message news:ga84hi$r6q$1@xxxxxx Quote: >>> Nel suo scritto precedente, Pegasus (MVP) ha sostenuto : >>>> "AleP" <a@xxxxxx> wrote in message news:ga7vpi$8sf$1@xxxxxx >>>>> Hi all, >>>>> I have a folder with same backup file and I must delete the file older >>>>> than 4 days before. >>>>> How can I do with VBS Script? >>>>> thanks in advance >>>>> >>>> >>>> You need to specify your requirements more precisely: >>>> - Where does the drive/folder/file name come from? Is it fixed? User >>>> input? >>>> - When you say "older than 4 days before", do you mean "more than 4 days >>>> older than the original file" or "more than 4 days old, measured from >>>> today"? >>> >>> Hi. >>> The directory is fixed and the file name is 5 different >>> more than 3days from today >>> thanks a lot >>> >>> >> Try this: >> sFolder = "d:\temp\" >> sFile = "abc.txt" >> set iMaxAge = 5 >> Set oFSO = CreateObject("Scripting.FileSystemObject") >> If oFSO.FileExists(sFolder & sFile) Then >> Set oFile = oFSO.GetFile(sFolder & sFile) >> If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then >> WScript.Echo "oFile.Delete" >> End If >> End If >> >> When you're happy with the result, change this line >> WScript.Echo "oFile.Delete" to this one: >> oFile.Delete >> in order to activate the script. > thanks a lot automaticallu the delete as your vbs? thanks |
My System Specs![]() |
| | #7 (permalink) |
| | Re: VBS SCRIPT to clean OLD FILE On Sep 10, 10:07*am, AleP <a...@xxxxxx> wrote: Quote: > Dopo dura riflessione, AleP ha scritto : > > > > > > > Quote: > > Scriveva Pegasus (MVP) mercoledì, 10/09/2008: Quote: > >> "AleP" <a...@xxxxxx> wrote in messagenews:ga84hi$r6q$1@xxxxxx > >>> Nel suo scritto precedente, Pegasus (MVP) ha sostenuto : > >>>> "AleP" <a...@xxxxxx> wrote in messagenews:ga7vpi$8sf$1@xxxxxx > >>>>> Hi all, > >>>>> I have a folder with same backup file and I must delete the file older > >>>>> than 4 days before. > >>>>> How can I do with VBS Script? > >>>>> thanks in advance Quote: Quote: > >>>> You need to specify your requirements more precisely: > >>>> - Where does the drive/folder/file name come from? Is it fixed? User > >>>> input? > >>>> - When you say "older than 4 days before", do you mean "more than 4 days > >>>> older than the original file" or "more than 4 days old, measured from > >>>> today"? Quote: Quote: > >>> Hi. > >>> The directory is fixed and the file name is 5 different > >>> more than 3days from today > >>> thanks a lot Quote: Quote: > >> Try this: > >> sFolder = "d:\temp\" > >> sFile = "abc.txt" > >> set iMaxAge = 5 > >> Set oFSO = CreateObject("Scripting.FileSystemObject") > >> If oFSO.FileExists(sFolder & sFile) Then > >> *Set oFile = oFSO.GetFile(sFolder & sFile) > >> *If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then > >> * WScript.Echo "oFile.Delete" > >> *End If > >> End If Quote: Quote: > >> When you're happy with the result, change this line > >> * WScript.Echo "oFile.Delete" * * * to this one: > >> * oFile.Delete > >> in order to activate the script. Quote: > > thanks a lot > it's possibile to do a vbs that cycle all files in a folder and do > automaticallu the delete as your vbs? > thanks sFolder = "d:\temp\" set iMaxAge = 5 Set oFSO = CreateObject("Scripting.FileSystemObject") If oFSO.FolderExists(sFolder) Then for each oFile in oFSO.GetFolder(sFolder).Files If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then WScript.Echo "oFile.Delete" End If next End If You may also want to check out this on-line resources to help you in the future ... WSH 5.6 documentation download (URL all one line) http://www.microsoft.com/downloads/d...displaylang=en TechNet Script Center Sample Scripts (URL all one line) http://www.microsoft.com/downloads/d...a-b8814fe2da5a Tom Lavedas =========== http://members.cox.net/tglbatch/wsh/ |
My System Specs![]() |
| | #8 (permalink) |
| | Re: VBS SCRIPT to clean OLD FILE "AleP" <a@xxxxxx> wrote in message news:ga8kam$q8f$1@xxxxxx Quote: > Dopo dura riflessione, AleP ha scritto : Quote: >> Scriveva Pegasus (MVP) mercoledì, 10/09/2008: Quote: >>> "AleP" <a@xxxxxx> wrote in message news:ga84hi$r6q$1@xxxxxx >>>> Nel suo scritto precedente, Pegasus (MVP) ha sostenuto : >>>>> "AleP" <a@xxxxxx> wrote in message >>>>> news:ga7vpi$8sf$1@xxxxxx >>>>>> Hi all, >>>>>> I have a folder with same backup file and I must delete the file >>>>>> older than 4 days before. >>>>>> How can I do with VBS Script? >>>>>> thanks in advance >>>>>> >>>>> >>>>> You need to specify your requirements more precisely: >>>>> - Where does the drive/folder/file name come from? Is it fixed? User >>>>> input? >>>>> - When you say "older than 4 days before", do you mean "more than 4 >>>>> days older than the original file" or "more than 4 days old, measured >>>>> from today"? >>>> >>>> Hi. >>>> The directory is fixed and the file name is 5 different >>>> more than 3days from today >>>> thanks a lot >>>> >>>> >>> >>> Try this: >>> sFolder = "d:\temp\" >>> sFile = "abc.txt" >>> set iMaxAge = 5 >>> Set oFSO = CreateObject("Scripting.FileSystemObject") >>> If oFSO.FileExists(sFolder & sFile) Then >>> Set oFile = oFSO.GetFile(sFolder & sFile) >>> If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then >>> WScript.Echo "oFile.Delete" >>> End If >>> End If >>> >>> When you're happy with the result, change this line >>> WScript.Echo "oFile.Delete" to this one: >>> oFile.Delete >>> in order to activate the script. >> thanks a lot > it's possibile to do a vbs that cycle all files in a folder and do > automaticallu the delete as your vbs? > thanks > The line set iMaxAge = 5 must read iMaxAge = 5 The correction applies to Tom's modified version too. |
My System Specs![]() |
| | #9 (permalink) |
| | Re: VBS SCRIPT to clean OLD FILE Il giorno Wed, 10 Sep 2008 07:29:38 -0700 (PDT), Tom Lavedas <tglbatch@xxxxxx> ha scritto: Quote: >Try something like this ... > >sFolder =3D "d:\temp\" >set iMaxAge =3D 5 >Set oFSO =3D CreateObject("Scripting.FileSystemObject") >If oFSO.FolderExists(sFolder) Then > for each oFile in oFSO.GetFolder(sFolder).Files > If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then > WScript.Echo "oFile.Delete" > End If > next >End If days. As the OP is italian, I have some code commented in italian in my web pages. Dim fso, f, f1, fc Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder("J:\aaaa") Set fc = f.Files For Each f1 in fc If DateDiff("d", f1.DateLastModified, Now) > 30 Then f1.Delete End If Next Set fso = Nothing Set f = Nothing Set fc = Nothing -- Giovanni Cenati (Bergamo, Italy) Write to "Reventlov" at katamail com http://digilander.libero.it/Cenati (Esempi e programmi in VbScript) -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Script to clean up Flash Player old files | VB Script | |||
| problem passing args to script 'There is no script engine for file extenstion' | VB Script | |||
| file copy operations using source file input and script? | PowerShell | |||
| Script file has 'OS Handle' error when run from script | PowerShell | |||
| Can you drag-n-drop a file on top of a PS script to run the script? | PowerShell | |||