Page 1 of 3 123>
Topic Options
#156879 - 2006-02-08 01:02 AM Dir() Help
thepip3r Offline
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
#156880 - 2006-02-08 01:25 AM Re: Dir() Help
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I see your problem. You are mixing up your users Joe Blow and Jane Doe.
Have you had a look at the Bryce's DirPlus() UDF?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#156881 - 2006-02-08 01:27 AM Re: Dir() Help
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
FileList() UDF
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#156882 - 2006-02-08 01:38 AM Re: Dir() Help
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Thanx gents. I looked at DirWalker(), DirScan(), skipped over DirPlus() and saw DirList() as it looked like it would give me the results I'd want. I need to grab the files sizes of these file types so it looks like I'm going to try DirPlus() as I think it will allow me to return the info I need. Thanx for the response gents.
Top
#156883 - 2006-02-08 03:09 AM Re: Dir() Help
thepip3r Offline
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 Offline
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
#156885 - 2006-02-08 04:13 AM Re: Dir() Help
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
No, I get the exact same issue as my last script. Without the @ERRORs it's just a blank screen, when you add the @ERRORs it's all 2's
Top
#156886 - 2006-02-08 04:17 AM Re: Dir() Help
Shawn Administrator Offline
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 Offline
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 Offline
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
#156889 - 2006-02-08 04:36 AM Re: Dir() Help
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
hmmm that's interesting, I just copied that whole script and replaced it in my kix file and I still got the same results. Any idea why shawn?
Top
#156890 - 2006-02-08 04:40 AM Re: Dir() Help
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
What are you getting exactly ? A black screen ? is it crunching the drive though ? those recursive functions can be real pigs.
Top
#156891 - 2006-02-08 04:44 AM Re: Dir() Help
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hey Les - what you get if you run this code snippet ?
Top
#156892 - 2006-02-08 06:23 AM Re: Dir() Help
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
If I don't have the sleep command in there, the window just opens up and closes, when I add the sleep command, it just brings up a black screen and returns no info. When I add those @ERROR commands in front of the $z = Dir( command, I get an error code of 2 and then the script sleeps, and exits.

Edit: It's morning here in Iraq and I'm going to sleep. Just fyi Shawn in case you keep looking at this. I'll readdress later this afternoon.


Edited by thepip3r (2006-02-08 06:24 AM)

Top
#156893 - 2006-02-08 09:18 AM Re: Dir() Help
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I guess I should ask the obvious question...

Error 2 is a standard DOS error "The system cannot find the file specified."

Are you certain that the path is correct and that there are files present that match the wildcard?

If there are no matching files in the directory then an error 2 would be an appropriate error value.

Top
#156894 - 2006-02-08 09:56 AM Re: Dir() Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
my question would be, why you still use dir???
Code:

$ = SetOption("WrapAtEOL","On")

$dir = 'C:\Documents and Settings\cameron.wilson\Desktop'
dim $paths

for each $file in DirPlus($dir,"/s /f mp3 avi jpg gif")
$path = left($file.path, instrrev($file.path,"\"))
if -1 = ascan($paths,$path)
redim preserve $paths[ubound($paths)+1]
$paths[ubound($paths)] = $path
? $path
endif
Next

"press any key to quit "
get $

_________________________
!

download KiXnet

Top
#156895 - 2006-02-08 07:04 PM Re: Dir() Help
NTDOC Administrator Offline
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 Offline
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
#156897 - 2006-02-08 08:08 PM Re: Dir() Help
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

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.



K, then what's Shawn's excuse?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#156898 - 2006-02-08 08:15 PM Re: Dir() Help
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
eh ? whats my excuse for what ? using dir() ?

piper - I get this with your stripped-down script ...

C:\>kix32 test

E:\Documents and Settings\Administrator\Desktop\test

btw - what version you have for \system32\scrrun.dll ?

Top
Page 1 of 3 123>


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

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.085 seconds in which 0.035 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