Torque Posted April 3, 2006 Posted April 3, 2006 :"> 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.
Moderators SmOke_N Posted April 3, 2006 Moderators Posted April 3, 2006 (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 EndFuncEdit: You may need beta for this. Edited April 3, 2006 by SmOke_N 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.
Torque Posted April 3, 2006 Author Posted April 3, 2006 Thanks for your answers. Now I can rebuild my script. I will post it as soon as it works ...
Torque Posted April 3, 2006 Author Posted April 3, 2006 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now