J'ai voulu faire un script qui permet de trouver des fichiers données dans un dossier aléatoire du bureau. Je suis donc tombé sur un sujet du forum autoIT anglais et j'ai trouvé une fonction je pense qui me permetterais de faire ce que je voudrais.
Voici le code :
Code : Tout sélectionner
;===============================================================================
;
; Description: lists all files and folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax: _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
; Parameter(s): $sPath = Path to generate filelist for
; $iFlag = determines weather to return file or folders or both
; $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
; $iFlag=0(Default) Return both files and folders
; $iFlag=1 Return both files and folders with full path
; $iFlag=2 Return Files Only
; $iFlag=3 Return Files Only with full path
; $iFlag=4 Return Folders Only
; $iFlag=5 Return Folders Only with full path
;
; Requirement(s): None
; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
; @Error=1 Path not found or invalid
; @Error=2 Invalid $sFilter
; @Error=3 Invalid $iFlag
; @Error=4 No File(s) Found
;
; Author(s): SolidSnake <MetalGX91 at GMail dot com> (Modified by mrbond007)
; Note(s): The array returned is one-dimensional and is made up as follows:
; $array[0] = Number of Files\Folders returned
; $array[1] = 1st File\Folder
; $array[2] = 2nd File\Folder
; $array[3] = 3rd File\Folder
; $array[n] = nth File\Folder
;
; Special Thanks to Helge and Layer for help with the $iFlag update
;===============================================================================
Func _FileListToArray($sPath, $sFilter, $iFlag)
Local $hSearch = "", $sFile = 0, $asFileList = ""
If Not FileExists($sPath) Then Return SetError(1, 1, "")
If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringInStr($sFilter, "|")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "")
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2 Or $iFlag = 3 Or $iFlag = 4 Or $iFlag = 5) Then Return SetError(3, 3, "")
$hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
If $hSearch = -1 Then Return SetError(4, 4, "")
While 1
$sFile = FileFindNextFile($hSearch)
If @error Then
SetError(0)
ExitLoop
EndIf
If $iFlag = 0 Then $asFileList = $asFileList & $sFile & "|"
If $iFlag = 1 Then $asFileList = $asFileList & $sPath & "\" & $sFile & "|"
If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then $asFileList = $asFileList & $sFile & "|"
If $iFlag = 3 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then $asFileList = $asFileList & $sPath & "\" & $sFile & "|"
If $iFlag = 4 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then $asFileList = $asFileList & $sFile & "|"
If $iFlag = 5 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then $asFileList = $asFileList & $sPath & "\" & $sFile & "|"
WEnd
FileClose($hSearch)
Return StringSplit(StringTrimRight($asFileList, 1) , "|")
EndFunc$array[0] = Number of Files\Folders returned
; $array[1] = 1st File\Folder
; $array[2] = 2nd File\Folder
; $array[3] = 3rd File\Folder
; $array[n] = nth File\Folder
Mais ou sont-ils placés ? Es ce qu'il faut que je les mettent ? Si oui, ou sa ?
Merci,
JW


