Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VBS SCRIPT to clean OLD FILE

Reply
 
Old 09-10-2008   #1 (permalink)
AleP


 
 

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
Old 09-10-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

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
>
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
Old 09-10-2008   #3 (permalink)
AleP


 
 

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"?
Hi.
The directory is fixed and the file name is 5 different
more than 3days from today
thanks a lot


My System SpecsSystem Spec
Old 09-10-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

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
>
>
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
Old 09-10-2008   #5 (permalink)
AleP


 
 

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.
thanks a lot


My System SpecsSystem Spec
Old 09-10-2008   #6 (permalink)
AleP


 
 

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
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
Old 09-10-2008   #7 (permalink)
Tom Lavedas


 
 

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
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
Old 09-10-2008   #8 (permalink)
Pegasus \(MVP\)


 
 

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
>
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
Old 09-11-2008   #9 (permalink)
Reventlov


 
 

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

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46