Jump to content
Sign in to follow this  
birdofprey

Hidden limits or maybe just wrong characters in path or path too long ?

Recommended Posts

birdofprey

Simply put I have a few functions that don't work together as expected. One of these is "trimming" a return value or something. One of them creates an array with all the subfolders of a specified folder. The other one, looks for and counts *.mp3 files in each of this folders, and even returns an array which let's me know how many files I have in each directory. It's actually working, and I thought I eliminated the bugs. But I just now observed, that I don't get all the files returned on one of my partitions.

In one case there's a really long directory, E:\applications\apps\c\miranda\miranda\Received Files\laura.gy\ in which there are a couple of these files but they only get returned if I choose to browse into the directory deeply, as in if I browse into the last two, the files will be found, but only in this case. I have another shorter one too, dour folders. So, again, not even one file from those folders are found. But the folders are returned in the console. I don't get it. :) And it's not dots nor spaces that cause the problem. Any ideas what goes wrong here ?

Func _SubFoldersToArray($sPath); do not byref; THIS CREATES JUST A LIST OF SUBFOLDERS !!!!!!!!!!!!!!!!
    ConsoleWrite(@ScriptLineNumber & ' _subfolderstoarray called' & @lf)
    Local $i, $j, $rlist[1]=[0], $blist, $alist=_FileListToArray ($sPath, '*', 2)
    If IsArray ($alist) Then
        For $i=1 To $alist [0] 
            _ArrayAdd ($rlist, $sPath & "\" & $alist [$i])
            $blist = _SubFoldersToArray ($sPath & "\" & $alist [$i])
            If $blist[0]>0 Then
                For $j=1 To $blist [0]
                    _ArrayAdd ($rlist, $blist [$j])
                Next
            EndIf
        Next
    EndIf
    $rlist [0] = UBound ($rlist); -1 plus the "sPath" one... so it's 0
;~  _ArrayInsert ( $rlist, 1, $sPath ); DON'T FORGET THE DIRECTORY IT SELF !!! - will be added by fin... in order to avoid repetition
;      Dis ($rlist, ( "-- Subfol2a" ) );uncommenting will slow you down
    Dim $r[2] = [$rlist, $sPath]
    Return $r
EndFunc
Func fin (ByRef $r); getting the list of files for each subfolder - and now getting files for the folder too !!!
    $rlist = $r[0]
    $ofolder = $r[1]
    _ArrayInsert ( $rlist, 1, $ofolder )
        Dis ($rlist, ( "!-- Subfol2a as returned to fin" ) )
        ConsoleWrite(@ScriptLineNumber & 'fin called' & @lf)
    Local $filelist[1] = [0]
    Global $indexlist[1] = [0]
    for $i = 1 to $rlist[0]; for each subfolder... get a list of mp3s... step control here ! ####################
        $files =_FileListToArray ( $rlist[$i], "*.mp3", 1)
        If IsArray ($files) then
            for $j = 1 to $files [0]
                $files [$j] = $rlist[$i] & "\" & $files [$j]
            Next
            Redim $indexlist[$i + 1]
            $indexlist[$i] = UBound ($files) - 1
            ConsoleWrite ("-- ! " & UBound ($files) & " " & $i & @LF)
            $filelist = _ArrayMerge ( $filelist, $files )
        EndIf
    Next
    $filelist[0] = UBound ($filelist) - 1;how many folders ?
    $indexlist[0] = UBound ($indexlist) - 1
    Dis ( $filelist, "--Fin" )
    Dis ( $indexlist, "--Findex" )
    Return $filelist
EndFunc
Func _ArrayMerge (ByRef $array1, ByRef $array2 )
    ConsoleWrite(@ScriptLineNumber & 'arraymerge called' & @lf)
    Select
        Case $array1[0] = 0
            Dis ($array1, @ScriptLineNumber)
            $array1 = $array2           
        Case Not IsArray ($array1)
            Dis ($array1, @ScriptLineNumber)
            $array1 = $array2
        Case IsArray ($array1)
            _ArrayDelete ( $array1, 0 )
            _ArrayDelete ( $array2, 0 )
            ReDim $array1[UBound($array1) + UBound($array2) ]
            For $x = 0 To UBound($array2) - 1
                $array1[UBound($array1) - UBound($array2) + $x] = $array2[$x]
            Next
            ReDim $array1 [UBound($array1) + 1]
            For $x = UBound($array1) - 1 To 1 step -1
                $array1[$x] = $array1[$x - 1]
            Next
    EndSelect
    $array1[0] = UBound($array1) - 1
;~ _ArrayDisplay($array1, "test")
    Return $array1
EndFunc
Func Dis($array, $ln); Displayes arrays to the console.
;~  ConsoleWrite(@ScriptLineNumber & 'dis called' & @lf)
    For $v = 0 to UBound($array) - 1
        ConsoleWrite( $ln & " array: " & $v & ": " & $array[$v] & @crlf )
    Next
EndFunc

Edit: I tried to include the autoitcode into a code box in order to limit the numbers of lines, but it didn't work out, so could someone enlighten me please ? How do I limit the height of the autoit-codebox ? what's the BB code here ?

Edited by birdofprey

Share this post


Link to post
Share on other sites
Valuater

Maybe, Because

_FileListToArray() will only look 2 folders deep... so

Func _SubFoldersToArray($sPath); do not byref; THIS CREATES JUST A LIST OF SUBFOLDERS !!!!!!!!!!!!!!!!

ConsoleWrite(@ScriptLineNumber & ' _subfolderstoarray called' & @lf)

Local $i, $j, $rlist[1]=[0], $blist, $alist=_FileListToArray ($sPath, '*', 2)

If IsArray ($alist) Then

For $i=1 To $alist [0]

_ArrayAdd ($rlist, $sPath & "\" & $alist [$i])

$blist = _SubFoldersToArray ($sPath & "\" & $alist [$i])

If ...

will only look "about" 4 folders deep

if you take a look at my "Script and Text Manager"'s search engine you will find what you are looking for

http://www.autoitscript.com/forum/index.ph...st&p=141335

8)

EDIT:

[ codebox][ autoit].... [ /autoit][ /codebox]

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
birdofprey

Thank you for trying but that's not it. You see, I make the mistake of editing portions of my code with gaps of days. I changed the return value into an array last time and forgot to adjust the rest of the function.

Here's the right way to do it, maybe someone will need this

Func _SubFoldersToArray($r) ; do not byref; THIS CREATES JUST A LIST OF SUBFOLDERS !!!!!!!!!!!!!!!!
    If IsArray ($r) Then
        $sPath = $r[0]
        $ofolder = $r[1]
    Else
        $sPath = $r
    EndIf                           ; this was the missing part
    ConsoleWrite(@ScriptLineNumber & ' _subfolderstoarray called' & @lf)
    Local $i, $j, $rlist[1]=[0], $blist, $alist=_FileListToArray ($sPath, '*', 2)
    If IsArray ($alist) Then
        For $i=1 To $alist [0] 
            _ArrayAdd ($rlist, $sPath & "\" & $alist [$i])
            $r2 = _SubFoldersToArray ($sPath & "\" & $alist [$i])
            $blist = $r2[0]    ; another line that had to be added
            If $blist[0]>0 Then
                For $j=1 To $blist [0]
                    _ArrayAdd ($rlist, $blist [$j])
                Next
            EndIf
        Next
    EndIf
    $rlist [0] = UBound ($rlist) - 1
;   Dis ($rlist, ( "-- Subfol2a" ) )
    Dim $r[2] = [$rlist, $sPath]
    Return $r
EndFunc
Func fin (ByRef $r) ; getting the list of files for each subfolder - and now getting files for the folder too !!!
    $rlist = $r[0]
    $ofolder = $r[1]
    _ArrayInsert ( $rlist, 1, $ofolder )
    $rlist [0] = UBound ($rlist) - 1
        Dis ($rlist, ( "!-- Subfol2a as returned to fin" ) )
        ConsoleWrite(@ScriptLineNumber & 'fin called' & @lf)
    Local $filelist[1] = [0]
    Global $indexlist[1] = [0]
    for $i = 1 to $rlist[0]
        $files =_FileListToArray ( $rlist[$i], "*.mp3", 1)
        If IsArray ($files) then
            for $j = 1 to $files [0]
                $files [$j] = $rlist[$i] & "\" & $files [$j]
            Next
            Redim $indexlist[$i + 1]
            $indexlist[$i] = UBound ($files) - 1
            ConsoleWrite ("-- ! " & UBound ($files) & " " & $i & @LF)
            $filelist = _ArrayMerge ( $filelist, $files )
        EndIf
    Next
    $filelist[0] = UBound ($filelist) - 1 ;how many folders ?
    $indexlist[0] = UBound ($indexlist) - 1
    Dis ( $filelist, "--Fin" )
;~  Dis ( $indexlist, "--Findex" )
    $indexlist = TIndex ( $indexlist )
    Dis ( $indexlist, "--Tindex" )
    Return $filelist
EndFunc
Func TIndex ($_indexlist)
    Dim $_truncatedindexlist[1] = [0]
    Local $j = 0
    For $i = 1 to $_indexlist[0]
        If IsNumber ($_indexlist[$i]) Then
            $j = $j + 1
            ReDim $_truncatedindexlist[$j + 1]
            $_truncatedindexlist[$j] = $_indexlist[$i]
        EndIf
    Next
    $_truncatedindexlist[0] = UBound ($_truncatedindexlist) - 1
    ;adding them up
    For $i = 2 to $_truncatedindexlist[0]
        $_truncatedindexlist[$i] = $_truncatedindexlist[$i] + $_truncatedindexlist[$i-1]
    Next
    Return $_truncatedindexlist
EndFunc

Edit: removed irrelevant comments

Edit 2: a line was missing

Edited by birdofprey

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×