Sign in to follow this  
Followers 0
Justmobile

Sorting files

4 posts in this topic

Hi All,

See code:

; Read Folders from current scriptdir in variabel $Folder

$teller = 0

$Foldername = @ScriptDir & "\*.*"

$search = FileFindFirstFile(""& $Foldername & "")

While 1

$Filenames = FileFindNextFile($search)

If @error Then ExitLoop

If $Filenames <> "XpIndexScriptAutoIt" Then

If StringInStr($filenames ,".") = 0 Then

$teller = $teller + 1

$Folder[ $teller ] = $Filenames

EndIf

EndIf

Wend

This is a little script from my main source,

Does anyone knows how i can sort it ?, ($Folder [ $teller])= > contents?

cheers

Justmobile

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$asItem = _GetList("C:\*.*")
    for $nX = 1 to $asItem[0]
        MsgBox(0,$nx, $asItem[$nX]) 
    next

Func _GetList($psFolder)
;Sort a list of filenames or directories

    $sCmd = "dir " & $psFolder & " /b /on"    ;filenames and folders
    $sCmd = "dir " & $psFolder & " /b /on /a-d";folders, not filenames
    $sCmd = "dir " & $psFolder & " /b /on /ad";filenames, not folders

    $sFileList = "C:\~listfile.tmp"
    RunWait(@Comspec & " /c " & $sCmd & ">" & $sFileList,"",@SW_HIDE)    
    $sList = FileRead($sFileList,FileGetSize($sFileList))
    $sList = StringTrimRight(StringReplace($sList,@CRLF, @LF),1)
    $asList = StringSplit($sList,@LF)
    
  ;cleanup
    FileDelete($sFileList)

    Return $asList

EndFunc

.. hope this helps :ph34r:

Edit: included call to func, since this is the Scripts and Scraps forum

Edited by trids

Share this post


Link to post
Share on other sites

Great! Many thanks will help a lot.

Justmobile

Share this post


Link to post
Share on other sites

Here's what I came up with on my own (doesn't require file parsing)

#include <Array.au3>
#include <Constants.au3>

Global $iLine = 0
Global $sLine = ""
Global $aLine = ""
Dim $aFiles[30000]
$aRaw = Run(@ComSpec & " /c dir n:\music\*.mp3 /b /o /s", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $SLine = StdoutRead($aRaw)
    If @error Then ExitLoop
    $aLine = StringSplit($SLine, @CRLF)
    If $aLine[0] > 1 Then 
        For $i = 1 To $aLine[0]
            If $aLine[$i] = "" Then Continueloop
            $iLine = $iLine + 1
            $aFiles[$iLine] = $aLine[$i]
        Next
    Else
        $iLine = $iLine + 1
        $aFiles[$iLine] = $sLine
    EndIf
Wend

Thought it was odd that the first STDOUT line was just 1 line and most ofthe rest were ~255 lines long (hence the need for the 'If $aLine[0] > 1' line)

Granted, I need to make this more generic and function-ize it but it works super fast! Plus I can make use of all the DIR arguments.

All I have to do now is go back and update all my utils that use FileSearch to use this instead!


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

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  
Followers 0