Что нового

Зависание скрипта подсчета количества листов PDF

joparezzz

Новичок
Сообщения
62
Репутация
0
Скрипт хорошо работает когда папок и файлов PDF не так много.
Но когда папок около 100 и файлов около 3000 скрипт не доходит до конца, зависает.
Код:
#include <Array.au3>
#include <FileOperations.au3>
#include <File.au3>

$sFolder = "F:\archive\2018"
$timer = TimerInit()
$aFolderList = _FO_FolderSearch($sFolder, '', True, 125)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' сек'
_ArrayDisplay($aFolderList, $timer & ' - все папки')


$t = 0
For $i = 1 To $aFolderList[0]
$FileList = _FileListToArray($aFolderList[$i])
   For $j = 1 to $FileList[0]
	  $sFile = $aFolderList[$i] & '\' & $FileList[$j]
	  $sPages = _XFDF_Info($sFile, "Pages")

	  $t = $t + $j
	  ;ConsoleWrite($i & '.' & $j - 1 & @TAB & $aFolderList[$i] & @CRLF)
	  ConsoleWrite($t & @TAB & $i & '.' & $j & @TAB & $FileList[$j] & @TAB & StringStripCR($sPages) &  @CRLF)
	  ;ProcessClose($iPid)
	  sleep (100)
   Next
   ConsoleWrite( @CRLF)
Next


; #FUNCTION# ====================================================================================================================
; Name...........: _XFDF_Info
; Description....: Retrives informations from a PDF file
; Syntax.........: _XFDF_Info ( "File" [, "Info"] )
; Parameters.....: File    - PDF File.
;                  Info    - The information to retrieve
; Return values..: Success - If the Info parameter is not empty, returns the desired information for the specified Info parameter
;                          - If the Info parameter is empty, returns an array with all available informations
;                  Failure - 0, and sets @error to :
;                   1 - PDF File not found
;                   2 - Unable to find the external programm
; Remarks........: The array returned is two-dimensional and is made up as follows:
;                   $array[1][0] = Label of the first information (title, author, pages...)
;                   $array[1][1] = value of the first information
;                   ...
; ===============================================================================================================================
Func _XFDF_Info($sPDFFile, $sInfo = "")
    Local $sXPDFInfo = @ScriptDir & "\pdfinfo.exe"

    If NOT FileExists($sPDFFile) Then Return SetError(1, 0, 0)
    If NOT FileExists($sXPDFInfo) Then Return SetError(2, 0, 0)

    Local $iPid = Run(@ComSpec & ' /c "' &  $sXPDFInfo & ' "' & $sPDFFile & '"', @ScriptDir, @SW_HIDE, 2)

    Local $sResult
    While 1
        $sResult &= StdoutRead($iPid)
        If @error Then ExitLoop
    WEnd

	;ConsoleWrite($sResult & @CRLF)
    Local $aInfos = StringRegExp($sResult, "(?m)^(.*?): +(.*)$", 3)
    If Mod( UBound($aInfos, 1), 2) = 1 Then Return SetError(3, 0, 0)

    Local $aResult [ UBound($aInfos, 1) / 2][2]

    For $i = 0 To UBound($aInfos) - 1 Step 2
        If $sInfo <> "" AND $aInfos[$i] = $sInfo Then Return $aInfos[$i + 1]
        $aResult[$i / 2][0] = $aInfos[$i]
        $aResult[$i / 2][1] = $aInfos[$i + 1]
		;ConsoleWrite($sInfo & @CRLF)
    Next

    If $sInfo <> "" Then Return ""
    
    Return $aResult	
EndFunc ; ---> _XFDF_Info
 
Верх