Page 1 of 1 1
Topic Options
#168861 - 2006-10-04 11:15 AM delete folder with dirplus
Nexus Offline
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 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Quote:

Del - Deletes one or more files




Not Folders.

Top
#168863 - 2006-10-04 11:43 AM Re: delete folder with dirplus
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I do not see the question in your thread, but maybe you want to use
RD "directory" [/s]

Top
#168864 - 2006-10-04 11:45 AM Re: delete folder with dirplus
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Quote:

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







no kidding. You have a "IF - ELSE - ENDIF" - statement but you forgot to define the action (where i put the "???"). Plus, from $folders you get back full paths, like "C:\xxx\yyy\test" not just "test", so either you check with
Code:
if instr ($folders,"test") or  ....  


or you split $folders with "\" as a delimiter.
"Del" doesen't work neither,... ah witto said that already.


Edited by therob (2006-10-04 11:48 AM)
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#168865 - 2006-10-04 11:48 AM Re: delete folder with dirplus
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
There is no real problem with his code, very un-tidy but the problem is due to him trying to use the del command when trying to delete folders.

But the IF ELSE and ENDIF will work without putting anything in to the first IF statement, messy but will work. The full path is comming from DirPlus.

Top
#168866 - 2006-10-04 11:51 AM Re: delete folder with dirplus
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Depends. If he want to delete the "test"-folders, he will delete all but them instead.
Plus, as he check for "test" only, he never get any positive results, because of the missing path.
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#168867 - 2006-10-04 03:26 PM Re: delete folder with dirplus
Bryce Offline
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 Offline
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 Offline
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 Offline
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
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 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.072 seconds in which 0.037 seconds were spent on a total of 12 queries. Zlib compression enabled.

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