Sign in to follow this  
Followers 0
Torque

Folders And Files

5 posts in this topic

:"> Hi all,

Is there a good way to make the difference between a folder and a file ?

I was thinking about a thing like that :

If [this is a folder] Then 
ElseIf [this is a file] Then
Else
EndIf

But I don't really know how to do it ...

Any idea ?

Thanks.

Share this post


Link to post
Share on other sites



Take a look at FileGetAttrib() in the help file.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here try this, I threw it together quickly, but I think it will still work well:

#include <file.au3>

$Test = _ReturnFoldersFiles(@DesktopDir, 1)
For $i = 1 To UBound($Test) - 1
    MsgBox(0, 'Test', 'File ' & $i & @CR & $Test[$i])
Next

$Test2 = _ReturnFoldersFiles(@DesktopDir, 2)
For $i = 1 To UBound($Test2) - 1
    MsgBox(0, 'Test', 'Folder ' & $i & @CR & $Test2[$i])
Next

Func _ReturnFoldersFiles($h_FileLocation, $i_Return_File_Folder); $i_Return_File_Folder: 1 for File 2 for Folder
    Local $ah_StoreFolders = '', $ah_StoreFiles = '', $h_FileFind = FileFindFirstFile($h_FileLocation & '\*.*')
    While 1
        $h_FileNext = FileFindNextFile($h_FileFind)
        If @error Then ExitLoop
        If StringInStr(FileGetAttrib($h_FileNext), 'd') Then
            $ah_StoreFolders &= $h_FileNext & Chr(01)
        Else
            $ah_StoreFiles &= $h_FileNext & Chr(01)
        EndIf
    WEnd
    $ah_StoreFolders = StringSplit(StringTrimRight($ah_StoreFolders, 1), Chr(01))
    $ah_StoreFiles = StringSplit(StringTrimRight($ah_StoreFiles, 1), Chr(01))
    If $i_Return_File_Folder = 1 And IsArray($ah_StoreFolders) Then Return $ah_StoreFolders
    If $i_Return_File_Folder = 2 And IsArray($ah_StoreFiles) Then Return $ah_StoreFiles
    SetError(1)
    Return 0
EndFunc
Edit: You may need beta for this.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites
:) Thanks for your answers. Now I can rebuild my script. I will post it as soon as it works ...

Share this post


Link to post
Share on other sites

:) Thanks for your answers. Now I can rebuild my script. I will post it as soon as it works ...

Here's the final code :

$attrib = FileGetAttrib(GUICtrlRead ($sdir))
If StringInStr($attrib, "D") Then
GuiCtrlCreateGroup ( "" , 4 , 8 , 120 , 40 )
$vol1 = DirGetSize (GUICtrlRead ($sdir),1)
$vol2 = Guictrlcreatelabel ( "Données : " & round ($vol1 [0] / 1024 / 1024 , 1 ) & " Mo" & @CRLF & "Nbr. fichiers : " & $vol1 [1] , 10 , 18 , 106 , 28)
GUICtrlSetFont ($vol2, 8 , 400)
GUICtrlSetColor(-1,0xFF0000)
Else
GuiCtrlCreateGroup ( "" , 4 , 8 , 120 , 30 )
$vol3 = FileGetSize(GUICtrlRead ($sdir))
$vol2 = Guictrlcreatelabel ( "Taille : " & round ($vol3 / 1024 / 1024 , 1 ) & " Mo" , 10 , 18 , 106 , 14 )
GUICtrlSetFont ($vol2, 9 , 400)
GUICtrlSetColor(-1,0xFF0000)
EndIf

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