|
|
|||||||
Hello all I am new here and had a question. I would like to run a script that looks for a specific file and then deletes that file. I am sure this is eay to do but have limited experience with kix and did not find anything when searching. Thanks |
||||||||
|
|
|||||||
open cmd prompt type: del /? Quote: Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\wheelerc>del /? Deletes one or more files. DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names names Specifies a list of one or more files or directories. Wildcards may be used to delete multiple files. If a directory is specified, all files within the directory will be deleted. /P Prompts for confirmation before deleting each file. /F Force deleting of read-only files. /S Delete specified files from all subdirectories. /Q Quiet mode, do not ask if ok to delete on global wildcard /A Selects files to delete based on attributes attributes R Read-only files S System files H Hidden files A Files ready for archiving - Prefix meaning not If Command Extensions are enabled DEL and ERASE change as follows: The display semantics of the /S switch are reversed in that it shows you only the files that are deleted, not the ones it could not find. you want to run a command something like: del c:\filename.ext /f /s /q |
||||||||
|
|
|||||||
Is there a way to do this from within KIX? I can delete the file but i do not know the exact location on every pc. Is there a way search an then if found delete? Thanks |
||||||||
|
|
|||||||
You may wanna look at the dirplus()-udf. |
||||||||
|
|
|||||||
read the switches again... |
||||||||
|
|
|||||||
I am working on a similar script. I have several thousand audio recordings. They are named with the following format YYYYMMDD-HHMMSS.wma The letters being:YearMonthDay-HourMinuteSecond. It is a long story, but the files are created on little hand held recorders, and the date and time info from these little recorders is extremely unreliable. I wrote a script that pulls the files from the recorders and puts them on a network share while also renaming them to the current date and time as described above. Now I need a script that purges any file more than 90 days old. I can use DateMath UDF to get the date, split and join it into the correct format and then issue a simple del statement such as: "Del /S C:\YYYYMMDD*". The problem is there is no /S switch in the Kix Del command, only in DOS. I can just send the command to a DOS shell, but that seems clumsy. Isn't there a better way? Here is what I have so far. Code: Break On $resultdate = Datemath(@DATE,-91) $Date = Join(Split($resultdate,'/'),"") ;Del /S C:\YYYYMMDD* What to do here??? ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;Functions ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function DateMath($ExpD1,$ExpD2) ; Author: ScriptLogic Corporation ; if both parameters are dates (yyyy/mm/dd), a positive ; integer indicating the days between the two dates will be returned. ; if the first is a date (yyyy/mm/dd) and the second is an integer ; (number of days), a new date will be returned. ; UDF dependencies: SerialDate, abs Select Case InStr($ExpD1,'/') And InStr($ExpD2,'/') ; two date passed - return daysbetween integer $DateMath=serialdate($ExpD1)-serialdate($ExpD2) If $DateMath<0 $DateMath=$DateMath*-1 EndIf Case InStr($ExpD1,'/') And 1-InStr($ExpD2,'/') ; date and a number passed - return date $ExpD2=0+$ExpD2 $Datemath=serialdate(serialdate($ExpD1)+$ExpD2) Case 1 ; incorrect parameters passed EndSelect EndFunction Function SerialDate($ExpD) ; Author: ScriptLogic Corporation ; parameter ($ExpD) must be a date (in the form of yyyy/mm/dd) ; or an integer previously derived by this function. ; if passed a date, it returns an integer. ; If passed an integer, it returns the date. ; Integers can be used for general-purpose math computations on dates ; and then converted back to dates by calling this function again. ; Algorithms were obtained from: http://www.capecod.net/~pbaum/date/date0.htm Dim $z,$h,$a,$b,$c,$y,$m,$d If InStr($ExpD,'/') ; date passed $y=Val(SubStr($ExpD,1,4)) $m=Val(SubStr($ExpD,6,2)) $d=Val(SubStr($ExpD,9,2)) If $m<3 $m=$m+12 $y=$y-1 EndIf ; return an integer $SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306 Else ; integer passed $z=0+$ExpD+306 ; cast numeric $h=100*$z-25 $a=$h/3652425 $b=$a-$a/4 $y=(100*$b+$h)/36525 $c=$b+$z-365*$y-$y/4 $m=(5*$c+456)/153 $d=$c-(153*$m-457)/5 If $m>12 $y=$y+1 $m=$m-12 EndIf $m=Right('0'+$m,2) $d=Right('0'+$d,2) ; return a string date $SerialDate=''+$y+'/'+$m+'/'+$d EndIf EndFunction |
||||||||
|
|
|||||||
Actually. Never mind. Now that I think about it, what I have been writing here will delete files that are exactly 90 days old. I need to delete all files that are MORE than 90 days old, so this wont work. Oh well. Back to the beginning for a re-tink. |
||||||||
|
|
|||||||
You can use the DirPlus() UDF to list through all the files and pull the date with FSO and even delete with FSO. There are several examples posted. |
||||||||
|
|
|||||||
Try this UDF instead... http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=82473 |
||||||||
|
|
|||||||
Or try CleanDirectory() - Cleans up the temporary directories (or any arbitrary directory) |
||||||||
|
|
|||||||
Thanks for the help guys. I ended up using DirPlus to search the directory, pull the FSO info for the Creation Date of the files. Then after some splitting and joining to get the date formats right, I used DateMath and SerialDate from ScriptLogic to determine how many days there are between the current date and the creation date of the file. If that date is greater than 90, then the file is deleted. I am posting the code here in case anyone else needs it. I use the creation date of the files in this circumstance because that is the only consistently correct info I can get based on our unique situation. Most everyone else will probably want to modify this code to delete based on some other attribute. Thanks again guys. Prerequisites DirPlus UDF & FSO Code: ;Description : Purge all files more than 90 days old. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Break On Call @SCRIPTDIR + "\DirPlus.udf" $Files = DirPlus("C:\test",'/A-D /S') For Each $File in $Files If $File $CreateDate=fnGetFileProp($File, DateCreated) $DateOnly=Split($CreateDate, " ") $Date=$DateOnly[0] $Array=Split($Date, "/") $Year=$Array[2] $Month=$Array[1] $Day=$Array[0] $FormattedDate=$Year + "/" + $Day + "/" + $Month $FileAge=DateMath($FormattedDate,@DATE) If $FileAge > "90" Del $File EndIf EndIf Next Quit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;Functions ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function fnGetFileProp($sFile,$sProp) Dim $objFSO, $objFile, $nul $objFSO = CreateObject("Scripting.FileSystemObject") If Not VarType($objFSO)=9 Exit 1 EndIf $objFile = $objFSO.GetFile($sFile) If Not VarType($objFile)=9 Exit 2 EndIf $nul=Execute("$$fnGetFileProp = $$objFile."+$sProp) If VarType($fnGetFileProp)=0 Exit 87 EndIf EndFunction Function DateMath($ExpD1,$ExpD2) Select Case InStr($ExpD1,'/') And InStr($ExpD2,'/') $DateMath=serialdate($ExpD1)-serialdate($ExpD2) If $DateMath<0 $DateMath=$DateMath*-1 EndIf Case InStr($ExpD1,'/') And 1-InStr($ExpD2,'/') $ExpD2=0+$ExpD2 $Datemath=serialdate(serialdate($ExpD1)+$ExpD2) Case 1 EndSelect EndFunction Function SerialDate($ExpD) Dim $z,$h,$a,$b,$c,$y,$m,$d If InStr($ExpD,'/') $y=Val(SubStr($ExpD,1,4)) $m=Val(SubStr($ExpD,6,2)) $d=Val(SubStr($ExpD,9,2)) If $m<3 $m=$m+12 $y=$y-1 EndIf $SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306 Else $z=0+$ExpD+306 $h=100*$z-25 $a=$h/3652425 $b=$a-$a/4 $y=(100*$b+$h)/36525 $c=$b+$z-365*$y-$y/4 $m=(5*$c+456)/153 $d=$c-(153*$m-457)/5 If $m>12 $y=$y+1 $m=$m-12 EndIf $m=Right('0'+$m,2) $d=Right('0'+$d,2) $SerialDate=''+$y+'/'+$m+'/'+$d EndIf EndFunction |