#168861 - 2006-10-04 11:15 AM
delete folder with dirplus
|
Nexus
Fresh Scripter
Registered: 2006-03-10
Posts: 11
Loc: Germany
|
Hi
I have a litte problem with "dirplus"
Code:
$folders = dirplus("c:\00", "/ad /s")
for each $folders in $folders ? $folders if $folders= ("test") or $folders= ("test2") else del "$folders" /s /h endif next
Function DirPlus($path,optional $Options, optional $f, optional $sfflag) If not vartype($f) DIM $f EndIf If not vartype($sfflag) DIM $sfflag EndIf
DIM $file, $i, $temp, $item, $ex1, $mask,$mask1,$maskArray,$maskarray1, $ex2, $code, $CodeWeight, $targetWeight, $weight, $masktrue DIM $tarray[0]
$ex1 = SetOption(Explicit,on) $ex2 = SetOption(NoVarsInStrings,on) $codeWeight = 0
If not Exist($path) $temp = SetOption(Explicit,$ex1) $temp = SetOption(NoVarsInStrings,$ex2) Exit @ERROR EndIf
If not vartype($f) $f = CreateObject("Scripting.FileSystemObject").getfolder($path) EndIf If @ERROR $temp = SetOption(Explicit,$ex1) $temp = SetOption(NoVarsInStrings,$ex2) Exit @ERROR EndIf
For Each $temp In Split($options,"/") $temp=Trim($temp) Select Case left($temp,1) = "s" If not vartype($sfflag) If Val(right($temp,-1)) = 0 $sfflag = -1 Else $sfflag = Val(right($temp,-1)) EndIf EndIf Case Left($temp,1) = "a" Select Case Right($temp,-1)="d" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 16 " ;"if $file.type = 'File Folder' " Case Right($temp,-1)="-d" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 16)=0 " ;"if $file.type <> 'File Folder' " Case Right($temp,-1)="s" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 4 " Case Right($temp,-1)="-s" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 4)=0 " Case Right($temp,-1)="h" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 2 " Case Right($temp,-1)="-h" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 2)=0 " Case Right($temp,-1)="r" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 1 " Case Right($temp,-1)="-r" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 1)=0 " Case Right($temp,-1)="a" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 32 " Case Right($temp,-1)="-a" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 32)=0 " EndSelect $code = $temp + "$weight=$weight+1 endif" +@CRLF + $code
Case Left($temp,1) = "m" $maskarray = Split(Right($temp,-2),"|") $codeweight = $codeweight + 1 $code = "$masktrue=0 for Each $mask in $maskarray if instr($file.name,$mask) $masktrue=1 " + "EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code Case Left($temp,1) = "f" $maskarray1 = Split(Right($temp,-2)," ") $codeweight = $codeweight + 1 $code = "$masktrue=0 for Each $mask1 in $maskarray1 if substr($file.name,Instrrev($file.name,'.')+1)" + "=$mask1 $masktrue=1 EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code
EndSelect Next $code = "$weight = 0 $targetWeight = " + $codeweight + @CRLF + $code $code = $code + "if $weight = $targetweight Exit 1 endif"
For Each $file In $f.subfolders If Execute($code) $tarray[$i] = $file $i = $i + 1 ReDIM preserve $tarray[$i] EndIf If $sfflag $temp = dirplus($file,$options,$file,$sfflag-1) For Each $item In $temp $tarray[$i] = $item $i = $i + 1 ReDIM preserve $tarray[$i] Next EndIf Next For Each $file In $f.files If Execute($code) $tarray[$i] = $file $i = $i + 1
ReDIM preserve $tarray[$i] EndIf Next
If $i ReDIM preserve $tarray[$i-1] $i=0 Else $tarray = 0 EndIf
$dirplus = $tarray $temp = SetOption(Explicit,$ex1) $temp = SetOption(NoVarsInStrings,$ex2) Exit @ERROR EndFunction
|
Top
|
|
|
|
#168862 - 2006-10-04 11:34 AM
Re: delete folder with dirplus
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
Quote:
Del - Deletes one or more files
Not Folders.
|
Top
|
|
|
|
#168867 - 2006-10-04 03:26 PM
Re: delete folder with dirplus
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Dirplus returns the COM object to the file system in question... so.
Code:
$folders = dirplus("c:\00", "/ad /s")
for each $folder in $folders ? $folder.name ? $folder.path
; dont delete the test or test 2 folder ????? if $folder.name = "test" or $folder.anme = "test2"
else $folder.delete endif next
|
Top
|
|
|
|
#168868 - 2006-10-04 08:39 PM
Re: delete folder with dirplus
|
Nexus
Fresh Scripter
Registered: 2006-03-10
Posts: 11
Loc: Germany
|
that sample code did exactly what I needed...thanks! 
my other problem is: How remove old Serverprofiles
Cu
|
Top
|
|
|
|
#168869 - 2006-10-05 12:18 PM
Re: delete folder with dirplus
|
bofh71
Fresh Scripter
Registered: 2005-09-26
Posts: 11
Loc: Denmark
|
Quote:
that sample code did exactly what I needed...thanks! : Cu
Would believe that the sample code came with a typo so that folder with the name test2 would be deleted as well, corrected below
Code:
$folders = dirplus("c:\00", "/ad /s")
for each $folder in $folders ? $folder.name ? $folder.path
; dont delete the test or test 2 folder ????? if $folder.name = "test" or $folder.name = "test2"
else $folder.delete endif next
Rgds Jan V.
|
Top
|
|
|
|
#168870 - 2006-10-05 06:09 PM
Re: delete folder with dirplus
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Those silly typos! 
Quote:
Quote:
that sample code did exactly what I needed...thanks! : Cu
Would believe that the sample code came with a typo so that folder with the name test2 would be deleted as well, corrected below
Code:
$folders = dirplus("c:\00", "/ad /s")
for each $folder in $folders ? $folder.name ? $folder.path
; dont delete the test or test 2 folder ????? if $folder.name = "test" or $folder.name = "test2"
else $folder.delete endif next
Rgds Jan V.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|