I'm trying to use this script to remove some old profiles but I kept getting this error.

Script error: Error in expression.!
Del $LPath + "\*.*" /c /f /h ;delete files in Folder root


So I changed that line to this.

shell '%ComSpec% /c rd /s /q "$LPath + "\*.*"" >nul 2>nul'

When that runs it delets everything in the current directory.
Here is the output.

NTUSER.DAT as of 5555555
Profile of User = . as of is deleted
NTUSER.DAT as of
Profile of User = . as of is deleted

I need to be able to delete SPECIFIC older profiles with a script(vbs, bat, kix, au3 are all acceptable).
Any suggestions?


Code:
;************************************************************************
;
;DelMachineProfiles
;
;************************************************************************
;Script to delete old profiles *
; *
;written by J.Maassen (www.JoeM.de) *
; *
;created on 11th october 2005 *
; *
;last time changed 12.oct.2005 18:10 utc *
;************************************************************************


$LPath="C:\Documents and Settings" ;path where the profiles are located
$Div = 31 ;number of days, the ntuser.dat which is going to be deleted should not written
$Result = ""

Del $LPath + "\*.*" /c /f /h ;delete files in Folder root

$User = DIR($LPath) ;read folder name

while $User <> "" and @ERROR = 0
;-------------------------------------------------------------------
;do not delete profile of some special users
;maybe this has to be changed on OS with an other language
;please check to adapt
;-------------------------------------------------------------------
if $User <> "Default User" AND $USER <> "All Users" AND $User <> "." AND $User <> ".."
$Result = GetFileTime($Lpath + $User + "\NTUSER.DAT") ;get date of file NTUSER.DAT
$ResultY = Substr ($Result,1,4)
$ResultM = Substr ($Result,6,2)
$ResultD = Substr ($Result,9,2)
$ResultS = VAL($ResultY) * 364 + VAL($ResultM) * 30 + VAL($ResultD) ;count a number of that date
?"NTUSER.DAT as of " + $Result
$DateY = Substr (@Date,1,4)
$DateM = Substr (@Date,6,2)
$DateD = Substr (@Date,9,2)
$DateS = VAL($DateY) * 364 + VAL($DateM) * 30 + VAL($DateD) ;count a number of the actual date
;-------------------------------------------------------------------
;I used the 364 and the 30 to have better a smaller number and maybe keep a profile one or two days longer
;better than deleting a profile too early
;-------------------------------------------------------------------
if $ResultS < $DateS - $Div ;Filedate older than actualdate minus $Div
$DPath = $Lpath + $User
DeleteFolder ($DPath) ;next step! delete folderstructure
;write log
?"Profile of User = " + $user + " as of " + $Result + " is deleted"
endif
endif
$User = DIR()
Loop

Exit

;************************************************************************

Function DeleteFolder ($path)

;************************************************************************
;Script to delete a whole Folderstructure even if it is not empty *
; *
;written by J.Maassen (www.JoeM.de) *
; *
;created on 11th october 2005 *
; *
;last time changed 12.oct.2005 18:10 utc *
;************************************************************************

Dim $file
Del ($path + "\*.*") /c /f /h /s ;delete all files in folder structure
$file = Dir($path + "\*.*") ;read folder name, there are no more any files in the folders
While $file <> "" AND @ERROR = 0 ;no error = subfolders exist
If $file <> "." AND $file <> ".." ;do not use the fist two folders
SetFileAttr($path + "\" + $file, 128) ;set folder attributes to normal
DeleteFolder ($path + "\" + $file) ;therefor that it is a subfolder call function recursively
RD ($DPath + "\" + $file) ;delete the folder (it is an empty folder, at least now)
EndIf
$file = Dir() ;read next folder name
Loop
RD $path ;after all subfolders are deleted, delete the starting folder

EndFunction



Edited by matthewst (2006-05-05 03:59 PM)