If you want folders and files ordered with folders first The you need to list them separately then append the 3 lists
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Array.au3>
Opt("ExpandEnvStrings", 1)
#include <File.au3>
Global $aFolderList = _FileListToArray(@WorkingDir, "*",$FLTA_FOLDERS)
Global $aFileList = _FileListToArray(@WorkingDir, "*",$FLTA_FILES)
_ArraySort($aFolderList)
_ArraySort($aFileList)
For $i = 1 To UBound($aFolderList) - 1
Local $sFilePath = $aFolderList[$i]
If Not FileWrite("elenco.txt", $sFilePath & @CRLF) Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
EndIf
Next
For $i = 1 To UBound($aFileList) - 1
Local $sFilePath = $aFileList[$i]
If Not FileWrite("elenco.txt", $sFilePath & @CRLF) Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
EndIf
Next