Please help I am looking for a vb/batch file that can delete files older
than xx days. Also the script should have a output so that l may Blat the
report.
Thx.
Please help I am looking for a vb/batch file that can delete files older
than xx days. Also the script should have a output so that l may Blat the
report.
Thx.
"Michael Kapangama" <MKAPANGAMA@SBCGLOBAL.NET> wrote in message
news:C415AAD5.382%MKAPANGAMA@SBCGLOBAL.NET...
> Please help I am looking for a vb/batch file that can delete files older
> than xx days. Also the script should have a output so that l may Blat the
> report.
>
> Thx.
>
The downloadable command xxcopy.exe has this facility already
built into it: xxcopy /rs /db#xx /ed /yy .. . .
If Windows PowerShell is an option:
$oldFiles = (get-date).addDays(-14)
dir <path> -recurse | where-object {-not $_.PSIsContainer -and ($_.lastWriteTime
-ge $oldFiles)} | remove-item -force -whatIf
Here's a breakdown of the command:
1. $oldFiles = (get-date).addDays(-14)
Create a date object and set it to today -14 days
2. dir <path> *.* -recurse
-recurse: Deletes the items in the specified locations and in all child
items of the locations.
3. where {-not $_.PSIsContainer -and $_.lastWriteTime -ge $oldFiles}
You pipe the dir command to the where-object cmdlet
-not $_.PSIsContainer: don't include directory objects
-and $_.lastWriteTime -ge $oldFiles: where each file's lastWriteTime property
is greater to or equel to 14 days
4. pipe the where clause to the remove-item cmdlet:
-force: Overrides restrictions that prevent the command from succeeding,
it also removes read only files
-whatIf: Describes what would happen if you executed the command without
actually executing the command.
When you're ready to go you can omit the -whatIf parameter
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
> Please help I am looking for a vb/batch file that can delete files
> older than xx days. Also the script should have a output so that l may
> Blat the report.
>
> Thx.
>
You can use forfiles.exe (native on server 2003 or downloadable from the server 2000 resource kit). There is a guide here:
http://www.jjclements.co.uk/index.ph...number-of-days
Last edited by Sarah Lou; 27-09-2008 at 04:00 PM.
Bookmarks