Netol Posted May 18 Share Posted May 18 Mi my friends, Just to ask to Code to obtain only the first file of the a lot of folders Link to comment Share on other sites More sharing options...
Xandy Posted May 18 Share Posted May 18 (edited) I think that there are many types of first file. I think you need to specify the type of sorting you require then we can determine the first file sorted in such a way. Edited May 18 by Xandy Netol and TheDcoder 2 Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Netol Posted May 18 Author Share Posted May 18 yes you are absolutely right to complement my request I need to take the first file from each folder that has a .DNG extension Link to comment Share on other sites More sharing options...
Xandy Posted May 19 Share Posted May 19 Are we going to pull the first .DNG file sorted by name, date, or file size? Netol and TheDcoder 2 Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Musashi Posted May 19 Share Posted May 19 9 hours ago, Netol said: I need to take the first file from each folder that has a .DNG extension Additional question : Are the files you are looking for located in one structure (a base directory and subdirectories), or are the directories spread all over the entire disk? "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Solution ioa747 Posted May 19 Solution Share Posted May 19 (edited) example to take the first file with a .txt extension expandcollapse popup; https://www.autoitscript.com/forum/topic/211902-code-to-obtain-only-the-first-file-of-the-a-lot-of-folders/ #include <File.au3> _FindAllDir(@MyDocumentsDir) ;---------------------------------------------------------------------------------------- Func _FindAllDir($dir) If StringRight($dir, 1) <> "\" Then $dir &= "\" $ArraySrtfiles = _FileListToArrayRec($dir, "*", $FLTAR_FOLDERS, $FLTAR_RECUR) If Not IsArray($ArraySrtfiles) Then ConsoleWrite($dir & " = Invalid input path" & @CRLF) Return Else Local $sResult For $x = 1 To $ArraySrtfiles[0] ;ConsoleWrite($dir & $ArraySrtfiles[$x] & @CRLF) $sResult = _FindFirstFile($dir & $ArraySrtfiles[$x], ".txt") If $sResult Then ConsoleWrite($dir & $ArraySrtfiles[$x] & $sResult & @CRLF) Next EndIf EndFunc ;==>_FindAllDir ;---------------------------------------------------------------------------------------- Func _FindFirstFile($dir, $Extension) ; Assign a Local variable the search handle of all files in the current directory. Local $hSearch = FileFindFirstFile($dir & "*" & $Extension) ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then ;ConsoleWrite("! Error: No files/directories matched the search pattern." & @CRLF) Return False EndIf ; Assign a Local variable the empty string which will contain the files names found. Local $sFileName = "" While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop ; By first matching ExitLoop If $sFileName Then ExitLoop WEnd ; Close the search handle. FileClose($hSearch) Return $sFileName EndFunc ;==>_FindFirstFile ;---------------------------------------------------------------------------------------- Edited May 19 by ioa747 corection Netol 1 I know that I know nothing Link to comment Share on other sites More sharing options...
Netol Posted May 19 Author Share Posted May 19 13 hours ago, Xandy said: Are we going to pull the first .DNG file sorted by name, date, or file size? It would be very good if you brought the first file ordered by date and then name, the size is not important Link to comment Share on other sites More sharing options...
Netol Posted May 19 Author Share Posted May 19 6 hours ago, ioa747 said: example to take the first file with a .txt extension expandcollapse popup; https://www.autoitscript.com/forum/topic/211902-code-to-obtain-only-the-first-file-of-the-a-lot-of-folders/ #include <File.au3> _FindAllDir(@MyDocumentsDir) ;---------------------------------------------------------------------------------------- Func _FindAllDir($dir) If StringRight($dir, 1) <> "\" Then $dir &= "\" $ArraySrtfiles = _FileListToArrayRec($dir, "*", $FLTAR_FOLDERS, $FLTAR_RECUR) If Not IsArray($ArraySrtfiles) Then ConsoleWrite($dir & " = Invalid input path" & @CRLF) Return Else Local $sResult For $x = 1 To $ArraySrtfiles[0] ;ConsoleWrite($dir & $ArraySrtfiles[$x] & @CRLF) $sResult = _FindFirstFile($dir & $ArraySrtfiles[$x], ".txt") If $sResult Then ConsoleWrite($dir & $sResult & @CRLF) Next EndIf EndFunc ;==>_FindAllDir ;---------------------------------------------------------------------------------------- Func _FindFirstFile($dir, $Extension) ; Assign a Local variable the search handle of all files in the current directory. Local $hSearch = FileFindFirstFile($dir & "*" & $Extension) ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then ;ConsoleWrite("! Error: No files/directories matched the search pattern." & @CRLF) Return False EndIf ; Assign a Local variable the empty string which will contain the files names found. Local $sFileName = "" While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop ; By first matching ExitLoop If $sFileName Then ExitLoop WEnd ; Close the search handle. FileClose($hSearch) Return $sFileName EndFunc ;==>_FindFirstFile ;---------------------------------------------------------------------------------------- Thanks a lot my friend, with this code i can made my program. best regards Xandy 1 Link to comment Share on other sites More sharing options...
ioa747 Posted May 19 Share Posted May 19 I just corrected it Netol 1 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted May 19 Share Posted May 19 (edited) another approach ; https://www.autoitscript.com/forum/topic/211902-code-to-obtain-only-the-first-file-of-the-a-lot-of-folders/ #include <File.au3> _FindAllDir(@MyDocumentsDir) ;---------------------------------------------------------------------------------------- Func _FindAllDir($dir) If StringRight($dir, 1) <> "\" Then $dir &= "\" $ArraySrtfiles = _FileListToArrayRec($dir, "*", $FLTAR_FOLDERS, $FLTAR_RECUR) If Not IsArray($ArraySrtfiles) Then ConsoleWrite($dir & " = Invalid input path" & @CRLF) Return Else Local $sResult For $x = 1 To $ArraySrtfiles[0] ;ConsoleWrite($dir & $ArraySrtfiles[$x] & @CRLF) $sResult = _FindAllFile($dir & $ArraySrtfiles[$x], "*.txt") If Not @error Then ConsoleWrite($sResult & @CRLF) Next EndIf EndFunc ;==>_FindAllDir ;---------------------------------------------------------------------------------------- Func _FindAllFile($dir, $FileMask) $ArraySrtfiles = _FileListToArrayRec($dir, $FileMask, $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT) If Not IsArray($ArraySrtfiles) Then Return SetError(1, 0, "") Else Local $sResult For $x = 1 To $ArraySrtfiles[0] $sResult = $dir & $ArraySrtfiles[$x] Return $sResult Next EndIf EndFunc ;==>_FindAllFile ;---------------------------------------------------------------------------------------- Edited May 19 by ioa747 Netol and robertocm 2 I know that I know nothing Link to comment Share on other sites More sharing options...
Netol Posted May 20 Author Share Posted May 20 Thanks a lot. Work fine! best regards ioa747 1 Link to comment Share on other sites More sharing options...
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