Sign in to follow this  
Followers 0
sylvanie

just a little routine

7 posts in this topic

I need often to store the output of the command dir.

So to avoid to repeat the same code, I have written this function, which store the output of dir in an array.

You can select the option "F" just to have files, "D" just to have directories and use a filter like *.exe ...

#cs
    function which store the output of dir in an array
    syntax : _arraydir(path,type,filter)
    with : 
        path: path where dir is running
        type :"F" to have just files, "D" to have just directories, "" all
        filter: "" all, "*.txt",......
    if success return an array, with array[0]=nbr of elements, array[1]=first folder or file....
    else return -1
#ce

#include <array.au3>

#region --- test of the function
$tab0=_arraydir(); returns all files and directories from the current directory
$tab1=_arraydir("C:\"); returns all files and directories from C:\
$tab2=_arraydir("C:\","D") ; returns all directories from C:\
$tab3=_arraydir("C:\","F") ; returns all files from C:\
$tab4=_arraydir("C:\","F","*.txt") ; returns all text files from C:\
_ArrayDisplay($tab0,@WorkingDir)
_ArrayDisplay($tab1,"C:\")
_ArrayDisplay($tab2,"C:\ directories")
_ArrayDisplay($tab3,"C:\ files")
_ArrayDisplay($tab4,"C:\ text files")

#endregion

Func _arrayDir($path="",$type="",$filter="*")
$tmp=@tempdir&"\temdir.txt"
Select
    Case $type="F"
        $type="/A:-D"
    Case $type="D"
        $type="/A:D"
    Case Else
        $type=""
EndSelect   
runwait(@comspec&" /c dir "&$type&" /B "&$filter&" > "&$tmp,$path,@SW_HIDE)
$size=FileGetSize($tmp)
$file=FileOpen($tmp,0)
if $file=-1 then return -1
$stock=FileRead($file,$size)
fileclose($file)
$stock=StringSplit($stock,@LF)
_ArrayDelete ( $stock, $stock[0] ); the last elt is "", so I prefer to remove it
$stock[0]=$stock[0]-1
FileDelete($tmp)
Return $stock
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

you should also look into stdin/out and do it that way

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

Hello

thanks for the remark, I have looked at stdin,out and err, but I don't succeed to get the info, when it's stored in these redirections :)

If you know how to do that, please could you explain me?

Thanks

PS : there is a bug in my last script :

$stock=StringSplit($stock,@LF)

has to be changed by :

$stock=StringSplit($stock,@CRLF,1)

Share this post


Link to post
Share on other sites

Opt ( "ProvideRunStdout", 1 )
$Dir = Run ( @ComSpec & " /c dir C:\" )
GUICreate ( "Dir STDOUT example", 400, 400 )
$edit = GUICtrlCreateEdit ( StdOutRead ( $Dir ), 0, 0, 400, 400 )
While 1
    $ret = StdOutRead ( $Dir )
    If $ret = "" Then ExitLoop
    GUICtrlSetData ( $edit, GuiCtrlRead ( $edit ) & @CRLF & $ret  )
WEnd
GUISetState ( )
Do
    Sleep ( 10 )
Until GUIGetMsg ( ) = -3


[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

thank you :D

I'll keep it preciously !

Unfortunately, it doesn't work with my version of Autoit (3.1.1) ("ProvideRunStdout" and StdOutRead aren't recognized).

I presume, you are using another version.

So I will waiting for the next versions to test it.

Thanks again for your help :)


Share this post


Link to post
Share on other sites

Download the newest beta from here :)


[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

thanks ! :)


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