Page 1 of 1 1
Topic Options
#193600 - 2009-04-26 03:42 PM Delete Temp-Dir
SteffenM Offline
Just in Town

Registered: 2009-04-26
Posts: 3
Loc: Germany
Hi,

I want to delete the Temp Dir under 'Local Settings'. I try with

DEL "%TEMP%" /h /s

in my login-script but it do not work and i do not know what's wrong?


Thanks, Steffen (Germany)

PS: KiX is still the best. Thanks for the new Beta and still working on it!

Top
#193601 - 2009-04-27 08:05 AM Re: Delete Temp-Dir [Re: SteffenM]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
If you do an @Error / @Serror immediatly after the DEL command, what is it telling you?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#193602 - 2009-04-27 12:13 PM Re: Delete Temp-Dir [Re: Gargoyle]
SteffenM Offline
Just in Town

Registered: 2009-04-26
Posts: 3
Loc: Germany
It shows '0' but the files and Dir's I can delete at explorer are still there after the DEL ...


Thanks, Steffen

Top
#193603 - 2009-04-27 02:11 PM Re: Delete Temp-Dir [Re: SteffenM]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Can you use the code below?

It uses the CleanDirectory() - Cleans up the temporary directories (or any arbitrary directory) UDF posted here by Sealeopard aka Jens that was especially designed the clean out directories.

 Code:
Break on

$rc = cleandirectory('YOURFOLDERGOESHERE', '*.*')
? $rc
Sleep

;=-=-=-=-=-=-=-=-=-= DO NOT MODIFY ANYTHING BELOW THIS LINE=-=-=-=-=-=-=-=-=-= 
;=-=-=-=-=-=-=-=-=-=THIS IS A UDF AND IT COMES READY FOR USE=-=-=-=-=-=-=-=-=-= 


;FUNCTION      CleanDirectory
;
;ACTION        Cleans up the temporary directory
;
;AUTHOR        Jens Meyer (sealeopard@usa.net)
;
;VERSION       1.42 (fixed a bug in the COUNTONLY counter resulting in all files being counted) 
;              1.41 (fixed bug in the OLDERAS parameter)
;              1.4  (added COUNTONLY flag)
;              1.31 (added flag to also delete hidden and system files)
;              1.3
;
;DATE CREATED  2001/12/18
;
;DATE MODIFIED 2006/04/13
;
;KIXTART       4.20+
;
;SYNTAX        CLEANDIRECTORY(DIRECTORY, FILTER [,DAYS, COUNTONLY])
;
;PARAMETERS    DIRECTORY
;              Required string/array containing the directory(s) to be cleaned
;
;              FILTER
;              Required string/array containing file filters for deletable files/folders, wildcards are supported
;
;              DAYS
;              Optional integer indicating how old a file/folder must be before it is deleted
;
;              COUNTONLY
;              Optional boolean preventing the files/folders to be deleted. UDF will only return the number of files
;              that match the age threshold.
;
;REMARKS       The function will recursively delete all matching files and empty subdirectories
;
;DEPENDENCIES  FULLFILE()    @ http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=81757
;              DATEMATH()    @ http://www.scriptlogic.com/kixtart/FunctionLibrary_ViewFunction.aspx?ID=DateMath
;
;RETURNS       Returns comma-separated number of deleted directories and files, otherwise 0
;
;EXAMPLE       $rc=cleandirectory('c:\temp','*.TMP',7)
;
;KIXTART BBS   http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82117
;
Function cleandirectory($directories, $filter, optional $olderas, optional $countonly)
	Dim $rc, $timediff, $filename, $filefilter, $tempdir
	Dim $filecount, $dircount
	
	$dircount = 0
	$filecount = 0
	
	$olderas = IIf(Val($olderas) > 0, Val($olderas), 0)
	$countonly = IIf(Val($countonly), 1, 0)
	
	If Not (VarType($directories) & 8192)
		$directories = Split($directories, '')
	EndIf
	If Not (VarType($filter) & 8192)
		$filter = IIf(Trim($filter), $filter, '*.*')
		$filter = Split($filter, '')
	EndIf
	
	For Each $tempdir in $directories
		If $tempdir <> '' And Exist($tempdir)
			For Each $filefilter in $filter
				If $filefilter <> ''
					$filefilter = fullfile($tempdir, $filefilter)
					$filename = Dir($filefilter, 1)
					While $filename <> '' And @ERROR = 0
						If $filename <> '.' And $filename <> '..'
							$filename = fullfile($tempdir, $filename)
							If GetFileAttr($filename) & 16
								$rc = cleandirectory($filename, $filter, $olderas, $countonly)
								If InStr($rc, ',')
									$rc = Split($rc, ',')
									$dircount = $dircount + $rc[0]
									$filecount = $filecount + $rc[1]
								EndIf
								$rc = SetFileAttr($filename, 128)
								If Not $countonly
									RD $filename
									If Not @ERROR
										$dircount = $dircount + 1
									EndIf
								EndIf
							Else
								$timediff = datemath(@DATE, Left(GetFileTime($filename), 10))
								If $timediff >= $olderas
									If $countonly
										$filecount = $filecount + 1
									Else
										$rc = SetFileAttr($filename, 128)
										Del $filename /c /f /h
										If Not @ERROR
											$filecount = $filecount + 1
										EndIf
									EndIf
								EndIf
							EndIf
						EndIf
						$filename = Dir('', 1)
					Loop
				EndIf
			Next
		EndIf
	Next
	
	$cleandirectory = '' + $dircount + ',' + $filecount
EndFunction
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193604 - 2009-04-27 02:54 PM Re: Delete Temp-Dir [Re: Mart]
SteffenM Offline
Just in Town

Registered: 2009-04-26
Posts: 3
Loc: Germany
Okay thanks. After import many UDF (cause of DEPENDENCIES) it seem to work, but I think it is a liitle bit oversized.


Steffen

Top
#193605 - 2009-04-27 03:05 PM Re: Delete Temp-Dir [Re: SteffenM]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Temp folders are always a pain to empty because some files/folders might be in use by the OS or some other application. You could keep the UDF's in one or more separate files and use call to call them from your main script. That way they are not in your main script but can be used in the same way. They will be stored in the memory of your system.

 Code:
call @scriptdir + "\udf1.kix"
call @scriptdir + "\udf2.kix"
call @scriptdir + "\udf3.kix"

all other code goes here......
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 693 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.054 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org