Windows Vista Forums

VBS SCRIPT to clean OLD FILE
  1. #1


    AleP Guest

    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 SpecsSystem Spec

  2. #2


    Pegasus \(MVP\) Guest

    Re: VBS SCRIPT to clean OLD FILE


    "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"?



      My System SpecsSystem Spec

  3. #3


    AleP Guest

    Re: VBS SCRIPT to clean OLD FILE

    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



      My System SpecsSystem Spec

  4. #4


    Pegasus \(MVP\) Guest

    Re: VBS SCRIPT to clean OLD FILE


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



      My System SpecsSystem Spec

  5. #5


    AleP Guest

    Re: VBS SCRIPT to clean OLD FILE

    Scriveva Pegasus (MVP) mercoledì, 10/09/2008:

    > "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



      My System SpecsSystem Spec

  6. #6


    AleP Guest

    Re: VBS SCRIPT to clean OLD FILE

    Dopo dura riflessione, AleP ha scritto :

    > Scriveva Pegasus (MVP) mercoledì, 10/09/2008:

    >> "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



      My System SpecsSystem Spec

  7. #7


    Tom Lavedas Guest

    Re: VBS SCRIPT to clean OLD FILE

    On Sep 10, 10:07*am, AleP <a...@xxxxxx> wrote:

    > Dopo dura riflessione, AleP ha scritto :
    >
    >
    >
    >
    >
    >
    >

    > > Scriveva Pegasus (MVP) mercoledì, 10/09/2008:

    > >> "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
    >

    > >>>> 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
    Try something like this ...

    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 SpecsSystem Spec

  8. #8


    Pegasus \(MVP\) Guest

    Re: VBS SCRIPT to clean OLD FILE


    "AleP" <a@xxxxxx> wrote in message news:ga8kam$q8f$1@xxxxxx

    > Dopo dura riflessione, AleP ha scritto :

    >> Scriveva Pegasus (MVP) mercoledì, 10/09/2008:

    >>> "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
    >
    As you may have discovered, there was a silly mistake in my original code.
    The line
    set iMaxAge = 5 must read
    iMaxAge = 5
    The correction applies to Tom's modified version too.



      My System SpecsSystem Spec

  9. #9


    Reventlov Guest

    Re: VBS SCRIPT to clean OLD FILE

    Il giorno Wed, 10 Sep 2008 07:29:38 -0700 (PDT), Tom Lavedas <tglbatch@xxxxxx> ha
    scritto:

    >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
    I saved this from a post on 23 sept 2003 from Dave Patrick. Deletes files older than 30
    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 SpecsSystem Spec

VBS SCRIPT to clean OLD FILE problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with my script to clean Log data. ibanez1998 PowerShell 0 28 Dec 2009
Script to clean up Flash Player old files Rich VB Script 13 15 Jul 2009
problem passing args to script 'There is no script engine for file extenstion' James VB Script 5 31 Oct 2008
Script file has 'OS Handle' error when run from script Jay PowerShell 1 18 Sep 2007
Can you drag-n-drop a file on top of a PS script to run the script? Jen Taylor PowerShell 6 06 Apr 2007