#156879 - 2006-02-08 01:02 AM
Dir() Help
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
I'm trying to run a loop so that dir will check some file extensions against a bunch of directories. My loops are working as they should all the way up until the most inner loop where I'm trying to get Dir() to loop through the paths\*.fileExtension. I know that the paths are coming out the way they should be because I'm echoing them to make sure. @Error reports a 2 (the manual doesn't say anything about an error 2 in Dir) and @SERROR doesn't report anything... does anyone have any thoughts?
Code:
Break On
$ = SetOption("WrapAtEOL","On")
$dir = 'C:\Documents and Settings\joe.doe\Desktop' $path = DirList($dir,1+2+4) $fileExt = ".mp3", ".avi", ".jpg", ".gif"
For $x=0 to ubound($path) If GetFileAttr($path[$x]) & 16 For Each $y in $fileExt ? $path[$x] + '*' + $y $z = Dir($path[$x] + '*' + $y) If @Error <> 0 ? @Error + ': ' + @SERROR Endif While $z <> "" and @ERROR = 0 ? $z $z = Dir() Loop Next Endif Next
sleep 20
|
|
Top
|
|
|
|
#156881 - 2006-02-08 01:27 AM
Re: Dir() Help
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
|
|
Top
|
|
|
|
#156883 - 2006-02-08 03:09 AM
Re: Dir() Help
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
Getting the EXACT same problem using DirScan(). Of course that might have something to do with the way I'm calling it since it's nearly identical to the previous... here is what my output looks like:
Code:
C:\Documents and Settings\cameron.wilson\Desktop\KiX\*.jpg 2 C:\Documents and Settings\cameron.wilson\Desktop\KiX\*.gif 2 C:\Documents and Settings\cameron.wilson\Desktop\KiX\Archive\*.mp3 2 C:\Documents and Settings\cameron.wilson\Desktop\KiX\Archive\*.avi 2 C:\Documents and Settings\cameron.wilson\Desktop\KiX\Archive\*.jpg 2 C:\Documents and Settings\cameron.wilson\Desktop\KiX\Archive\*.gif 2
Edit: Does the full name clear up the confusion Les? =P
Here is the code: Code:
Break On
$ = SetOption("WrapAtEOL","On")
$dir = 'C:\Documents and Settings\cameron.wilson\Desktop' $path = DirPlus($dir,"/ad /s") $fileExt = ".mp3", ".avi", ".jpg", ".gif"
For Each $x in $path For Each $y in $fileExt $z = Dir($x+'\*'+$y) ? $x+'\*'+$y If @Error <> 0 ? @Error + ': ' + @SERROR Endif While $z <> "" and @ERROR = 0 ? $z Loop Next Next
sleep 20
I still get Dir() returning an error code of 2 and nothing in @SERROR and my output looks fine. Any other ideas? My end goal here is to feed the script a "root" directory. The script pulls all subdirs under it and checks each one for files with the extensions in the above array, it it finds those files, it will get a file size and write both those values to a report. I haven't gotten nearly as far as I want because of my scan problem.
Can anyone see a problem with the way I'm using Dir()? I pretty much just used the example out of the Kix2010.doc file for Dir() so I'm not sure where I'm getting the error. Any and all help is always appreciated.
Edited by thepip3r (2006-02-08 03:10 AM)
|
|
Top
|
|
|
|
#156884 - 2006-02-08 03:29 AM
Re: Dir() Help
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Does this work any better:
Code:
Break On
$ = SetOption("WrapAtEOL","On")
$dir = '%USERPROFILE%\Desktop' $path = DirPlus($dir,"/ad /s") $fileExt = ".mp3", ".avi", ".jpg", ".gif"
For Each $x in $path For Each $y in $fileExt $z = Dir($x+'\*'+$y) While @ERROR = 0 ? $z $z = Dir() Loop Next Next
sleep 20
|
|
Top
|
|
|
|
#156886 - 2006-02-08 04:17 AM
Re: Dir() Help
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
weird, when I run it I get this:
Code:
C:\>kix32 test
loading.gif lock-broken.gif lock-insecure.gif lock-secure.gif cool_n.gif cry_n.gif money_n.gif sealed_n.gif smile_n.gif surprise_n.gif undecided_n.gif wink_n.gif yell_n.gif migrate.gif profileicon-large.gif img-align-bottom.gif img-align-left.gif img-align-middle.gif ...
|
|
Top
|
|
|
|
#156887 - 2006-02-08 04:27 AM
Re: Dir() Help
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
I copied and pasted the function from this thread (the one you asked me if it worked) and then copied and pasted the DirPlus() function from http://www.kixhelp.com/udfs/ and I just get a black screen.... hmm.. I don't know why it works for you and not me...
|
|
Top
|
|
|
|
#156888 - 2006-02-08 04:29 AM
Re: Dir() Help
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Heres all the code I have:
Code:
Break On
$ = SetOption("WrapAtEOL","On")
$dir = '%USERPROFILE%\Desktop' $path = DirPlus($dir,"/ad /s") $fileExt = ".mp3", ".avi", ".jpg", ".gif"
For Each $x in $path For Each $y in $fileExt $z = Dir($x+'\*'+$y) While @ERROR = 0 ? $z $z = Dir() Loop Next Next
;sleep 20
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
|
|
|
|
#156895 - 2006-02-08 07:04 PM
Re: Dir() Help
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Quote:
my question would be, why you still use dir???
My guess is because he's semi-new to KiXtart and not a Splitting/Redimming BASTA like you.  Haven't tried to run it, but looks good.
|
|
Top
|
|
|
|
#156896 - 2006-02-08 08:02 PM
Re: Dir() Help
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
Richard: Yes, while I am slow and that's a very good possibility that I didn't have the files on my desktop (but in this case I did), I tested out that possibility anyways. I added a directory to my Desktop called "test". I added just a single mp3 and wmv file and made the appropriate additions to the strings and got the exact same results. Here's what it looks like still with error 2 on the @ERROR.
$dir is reporting as: C:\Documents and Settings\cameron.wilson\Desktop\test obtained that by marking it in the cmd window, copying and pasting.
my "test" directory has: audio slave.mp3 movie_0001.wmv
and I tried to simplify the script as much as possible.
Code:
Break On
$ = SetOption("WrapAtEOL","On")
$dir = '%USERPROFILE%\Desktop\test' $path = DirPlus($dir,"/ad /s /f mp3 wmv")
? $dir
For Each $x in $path ? $x Next
Jooel: The reason I was still using Dir is because I saw that DirPlus() would apparently take file extensions and return them but when I tried to pass the extensions to them, I got blank results (like above) so I assumed that I was either passing it incorrectly or it wasn't working and getting the pathnames alone DID work so I tried to take it from that approach.
FYI: The script you provided yields almost the same resutls. I get this message and nothing else: "\*press any key to continue"...
Edit: Has anyone heard of a KiX specific function that ran differently on one machine than another? I could understand something like COM or where you could get an access denied problem but not something seeminly as simple as this... I even ran this on my coworker's machine to ensure it wasn't just mine.
Edited by thepip3r (2006-02-08 08:06 PM)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|