Старожил
Сообщения: 460
Благодарности: 152
|
Профиль
|
Отправить PM
| Цитировать
Цитата Yashied:
Способ 1. FileFindFirstFile() и FileFindNextFile()
Способ 2. _FileListToArray($sPath, '*', 1), затем удали из массива ненужные. »
|
а заме потом? сразу в ходе действия - заностить в массив только нужные.
вернее если тип файла не нужный - то не заносить.
И пример, с перебором подпапок:
читать дальше »
Код:
#region: - Options
Opt('GUIOnEventMode', 1)
Opt('MustDeclareVars', 1)
Opt('TrayIconDebug', 0)
Opt('TrayIconHide', 1)
#endregion
#region: - Include
#include <Array.au3>
#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#endregion
Local $sSerchInDirPath = 'd:\Обмен'
Local $sFilesSerchRegMask = '.*'
Local $sNoFilesSerchRegMask = '(?i)txt|lnk|jpg|exe|pdf|zip'
Local $sDirsSerchRegMask = '.*'
Local $aSubResultList = _GetFilesDirsList($sSerchInDirPath, $sFilesSerchRegMask, $sNoFilesSerchRegMask, $sDirsSerchRegMask, 1, 1, 0)
_ArrayDisplay($aSubResultList, 'Result list')
Func _GetFilesDirsList($sSerchInDirPath, $sFilesSerchRegMask='.*', $sNoFilesSerchRegMask='', $sDirsSerchRegMask='.*', $iAddFiles=1, $iAddDirs=0, $fSerchInWrongDir=1, $sRootPath=1, $fAddFromRootDir=1)
$sSerchInDirPath = StringRegExpReplace($sSerchInDirPath, '\\+$', '')
Local $aResultList[1], $aSubResultList[1], $aSub2ResultList[1], $hSerch, $sFileName, $sFilePath, $fAddToResult, $fIsDir, $fDirsSerchRegMask, $fFilesSerchRegMask, $fSerchInWrongDirSub, $fAddFromRootDirSub, $i
$aResultList[0] = 0
$hSerch = FileFindFirstFile($sSerchInDirPath & '\' & '*')
If @error Then Return SetError(1, 0, $aResultList)
If $sRootPath == 1 AND $iAddDirs == 1 AND $fAddFromRootDir Then
$aResultList[0] += 1
ReDim $aResultList[$aResultList[0]+1]
$aResultList[$aResultList[0]] = $sSerchInDirPath
EndIf
While 1
$sFileName = FileFindNextFile($hSerch)
If @error == 1 Then ExitLoop
$sFilePath = $sSerchInDirPath & '\' & $sFileName
$fAddToResult = 0
$fIsDir = StringInStr(FileGetAttrib($sFilePath), 'D')
$fDirsSerchRegMask = StringRegExp(StringRegExpReplace($sFilePath, '.+\\(.+)$', '\1'), $sDirsSerchRegMask)
$fFilesSerchRegMask = StringRegExp(StringRegExpReplace($sFilePath, '.+\\(.+)$', '\1'), $sFilesSerchRegMask)
If $fFilesSerchRegMask Then _
$fFilesSerchRegMask = NOT StringRegExp(StringRegExpReplace($sFilePath, '.+\\(.+)$', '\1'), $sNoFilesSerchRegMask)
$fAddFromRootDirSub = 1
If NOT $fDirsSerchRegMask Then $fAddFromRootDirSub = 0
If $fIsDir Then
If $iAddDirs == 1 AND $fDirsSerchRegMask Then $fAddToResult = 1
Else
If $iAddFiles == 1 AND $fFilesSerchRegMask AND $fAddFromRootDir Then $fAddToResult = 1
EndIf
If $fAddToResult Then
If $sRootPath == 1 AND NOT $fIsDir Then
$aResultList[0] += 1
ReDim $aResultList[$aResultList[0]+1]
$aResultList[$aResultList[0]] = $sFilePath
Else
$aSubResultList[0] += 1
ReDim $aSubResultList[$aSubResultList[0]+1]
$aSubResultList[$aSubResultList[0]] = $sFilePath
EndIf
EndIf
$fSerchInWrongDirSub = 1
If NOT $fSerchInWrongDir AND $fIsDir AND NOT $fDirsSerchRegMask Then $fSerchInWrongDirSub = 0
$aSub2ResultList[0] = 0
If $fIsDir Then
If $fSerchInWrongDirSub Then _
$aSub2ResultList = _GetFilesDirsList($sFilePath, $sFilesSerchRegMask, $sNoFilesSerchRegMask, $sDirsSerchRegMask, $iAddFiles, $iAddDirs, $fSerchInWrongDir, 0, $fAddFromRootDirSub)
EndIf
If $aSub2ResultList[0] Then
For $i = 1 To $aSub2ResultList[0]
$aSubResultList[0] += 1
ReDim $aSubResultList[$aSubResultList[0]+1]
$aSubResultList[$aSubResultList[0]] = $aSub2ResultList[$i]
Next
EndIf
WEnd
FileClose($hSerch)
For $i=1 To UBound($aSubResultList)-1
$aResultList[0] += 1
ReDim $aResultList[$aResultList[0]+1]
$aResultList[$aResultList[0]] = $aSubResultList[$i]
Next
Return SetError(0, 0, $aResultList)
EndFunc
|