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
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
"AleP" <a@xxxxxx> wrote in message news:ga7vpi$8sf$1@xxxxxxYou need to specify your requirements more precisely:
> 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"?
Nel suo scritto precedente, Pegasus (MVP) ha sostenuto :Hi.
> "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"?
The directory is fixed and the file name is 5 different
more than 3days from today
thanks a lot
"AleP" <a@xxxxxx> wrote in message news:ga84hi$r6q$1@xxxxxxTry this:
> 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
>
>
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.
Scriveva Pegasus (MVP) mercoledì, 10/09/2008:thanks a lot
> "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.
Dopo dura riflessione, AleP ha scritto :it's possibile to do a vbs that cycle all files in a folder and do
> 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
automaticallu the delete as your vbs?
thanks
On Sep 10, 10:07*am, AleP <a...@xxxxxx> wrote:Try something like this ...
> 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
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/
"AleP" <a@xxxxxx> wrote in message news:ga8kam$q8f$1@xxxxxxAs you may have discovered, there was a silly mistake in my original code.
> 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
>
The line
set iMaxAge = 5 must read
iMaxAge = 5
The correction applies to Tom's modified version too.
Il giorno Wed, 10 Sep 2008 07:29:38 -0700 (PDT), Tom Lavedas <tglbatch@xxxxxx> ha
scritto:I saved this from a post on 23 sept 2003 from Dave Patrick. Deletes files older than 30
>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)
--
| 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 |