Page 2 of 3 <123>
Topic Options
#156899 - 2006-02-08 08:22 PM Re: Dir() Help
Les Offline
KiX Master
*****

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

Hey Les - what you get if you run this code snippet ?



OOPS.. sorry, missed that Q

I get nothing, nada, squat, zippo... well you get what I mean.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#156900 - 2006-02-08 08:31 PM Re: Dir() Help
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
thepip3r,
i think the reason that you are only getting the dir and no files to display is because of this switch /ad, remove that switch so the line appears as:
Code:
$path      = DirPlus($dir,"/s /f mp3 wmv")

_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#156901 - 2006-02-08 08:48 PM Re: Dir() Help
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Shawn: scrrun.dll version = 5.6.0.8820

benny69: yes that was an oversight on my part. taking that out DOES display the files. the reason it was there is because i was originally just wanting the directories so I could run the *.ext search on them. thank you for pointing that out. I'll work with my script from there as Jooel's still returns a blank screen and he wrote it without the /ad switch.

Thanx again gents.

Top
#156902 - 2006-02-08 08:49 PM Re: Dir() Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
benny good point.
but don't think it's that.
herd that someone tried my code and it didn't work either.
I bet dirplus is broken.
_________________________
!

download KiXnet

Top
#156903 - 2006-02-08 08:55 PM Re: Dir() Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, I still didn't test my script but the display line was wrong.

should have been:
? $path

so, corrected the script above
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=156578#Post156578
_________________________
!

download KiXnet

Top
#156904 - 2006-02-08 09:03 PM Re: Dir() Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
thepip3r, did you try having all the extensions from your list?
it could be that my script fails because there is some issue with dirplus()

reducing the amount of extensions after /f could show already something.
_________________________
!

download KiXnet

Top
#156905 - 2006-02-08 11:12 PM Re: Dir() Help
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
This is your script in my implementation Jooel and I still get nothing:

Code:
Break On

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

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

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

"press any key to quit "
get $



My original script is working at this point so I'm going to try to take it's approach but I appreciate the help man. I really do.

Top
#156906 - 2006-02-08 11:49 PM Re: Dir() Help
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Crap, I just realized why I wanted to do the multiple loops Jooel since you were the one asking why I was still using Dir(). I wanted to script to work like this: start at a root directory, get all sub directories from the root and run a search on *.ext for each extension in my array so I could do a file size check on each one and write the results of the number and size of each file extension at each level of subdirectory. Does that make sense?
Top
#156907 - 2006-02-09 12:20 AM Re: Dir() Help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Well this won't give you the file size per sub-folder that you're now asking about, but it will give you the files and the sizes.
 
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $Dir, $Path, $Paths, $File, $Pause, $Index
$Dir = ExpandEnvironmentVars(ReadValue('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders','Desktop'))+'\Test'

$Index = 0
For Each $File In DirPlus($Dir,"/s /f mp3 mp4 mov avi mpg mpeg wmv asx divx mov jpg gif ")
$Path = Left($File.Path, InStrRev($File.Path,"\"))
If -1 = AScan($Paths,$Path)
ReDim Preserve $Paths[UBound($Paths)+1]
$Paths[UBound($Paths)] = $Path
EndIf
$Index=$Index+1
''+$Index +': ' +$File + ' ' + $File.Size ?
Next

'Press anykey to continue...' ?
Get $Pause

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
#156908 - 2006-02-09 12:27 AM Re: Dir() Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
pip3r, you didn't fix the script.
you still have:
? $x+'\*'+$y

use ? $path instead.
_________________________
!

download KiXnet

Top
#156909 - 2006-02-09 12:38 AM Re: Dir() Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
to make a script that counts the subdir sizes (only selected exts) as well, try this:
Code:

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

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

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]
redim preserve $pathSizes[ubound($pathSizes)+1]
$paths[ubound($paths)] = $path
endif
$pathSizes[ascan($paths,$path)] = $pathSizes[ascan($paths,$path)] + $file.size
Next

for $=0 to ubound($paths)
$paths[$] " " $pathSizes[$] ?
next

"press any key to quit "
get $

_________________________
!

download KiXnet

Top
#156910 - 2006-02-09 01:49 AM Re: Dir() Help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Well I'm not sure exactly why as I would think the UBound Redim Preserve would handle it but the folder path appears to be an issue for me when testing with %USERPROFILE%
I get: "ERROR : Error in expression: this type of array not supported in expressions.!"


Doing an If check seems to fix it. I'm sure Jooel or Bryce may be able to determine why but I don't have anymore time to work on it.

Code:
If $Path
$PathSizes[AScan($Paths,$Path)] = $PathSizes[AScan($Paths,$Path)] + $File.Size
EndIf


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

Registered: 2001-06-05
Posts: 22346
Loc: OK
kixtart bug.
_________________________
!

download KiXnet

Top
#156912 - 2006-02-09 09:34 AM Re: Dir() Help
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

kixtart bug.



Null element at end of array? Object not a simple file?

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
richie, doc said, he got rid of the error without the if'fing too.
if he placed "? $path" where the if stands now, the errors were not happening.

oh, haven't seen his test codes, but this was his resolution yesterday in IM conversation.

the bug comment was a merely a joke, but we all must have had those times with kixtart when there seems to be no explanation for the events taking place.
_________________________
!

download KiXnet

Top
#156914 - 2006-02-09 05:30 PM Re: Dir() Help
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I hope i understood this...

you have a folder with subfolders in it. and you want the size of the number of files in each subfolder of a given file type/types??

Code:

$root = "%userprofile%\desktop\temp"
$folders = dirplus($root,'/ad /s1')
for each $folder in $folders
$files = dirplus($folder.path,'/s /a-d /f mp3 avi jpg gif wmv')
for each $f in $files
$folsize = $folsize + $f.size
next
? $folsize " " $folder.path
$folsize=0
next



Edited by Bryce (2006-02-09 05:31 PM)

Top
#156915 - 2006-02-09 07:44 PM Re: Dir() Help
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
bryce, you have 2 loops.
I only had one
_________________________
!

download KiXnet

Top
#156916 - 2006-02-09 07:46 PM Re: Dir() Help
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
6 in one hand half dozen in the other....:D
Top
#156917 - 2006-02-09 11:29 PM Re: Dir() Help
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Bryce: .size and .path are methods of your variables right? is there anyway to return the extension as well so I can count the sizes for each extension?
Top
#156918 - 2006-02-10 02:45 PM Re: Dir() Help
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
those are FSO object's and i dont think that there is a file extension object... I think that there is a .filetype but will not give you what you want.

use something like this.
Code:
$ext = substr($file.name,Instrrev($file.name,'.')+1)



to give you the file extension in a variable.


Bryce

Top
Page 2 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.131 seconds in which 0.074 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