Скрипт создает список файлов по времени созданния/изменения/последнего доступа за период времени.
Код:
#cs ------------------------------------------------
AutoIt Version: 3.3.6.1
#ce -------------------------------------------------
;v.0.4
#include <Array.au3>
#include <Date.au3>
#include <FileOperations.au3>
Opt('MustDeclareVars', 1)
Global $sPathFind = StringLeft(@SystemDir, 3)
;Global $sMaska = "*.exe;*.dll;*.sys;*.cmd;*.bat;*.vbs;*.tmp;*.js;*.ini;*.bin;*.pif"
Global $sMaska = '*.exe|*.dll|*.sys|*.cmd|*.bat|*.vbs|*.tmp|*.js|*.ini|*.bin|*.pif'
Global $iPeriod = 2
CreateListFileTime($sPathFind, $sMaska, $iPeriod)
Func CreateListFileTime($sPathFindFile, $sMaskaFile = "*", $iPeriodTime = 7)
Local $sAttrib, $iDateCalc
Dim $aFileDirFind
;[0]-time create,[1]-time modif,[2]-time acces,[3]-path file
Dim $aFileDirDate[1][4]
Local $sDay = 'день', $sDays = 'дня', $s5Days = 'дней'
Local $t, $sTime
Local $count_progress = 0, $count_progress_all = 0
Local $MainLog = @WorkingDir & "\date_info.log" ;лог файл
Local $sCurrentDT_Epo = _Epoch_encrypt(_NowCalc()) ;текущая дата и время YYYY/MM/DD HH:MM:SS
Local $sec_day = 86400 ;3600 * 24
Local $file = FileOpen($MainLog, 10) ; which is similar to 2 + 8 (erase + create dir)
If $file = -1 Then
MsgBox(0, "Ошибка", "Не удалось открыть файл")
Exit
EndIf
Local $iTimer = TimerInit()
If ($iPeriodTime >= 20 And StringRight($iPeriodTime, 1) >= 2) Or ($iPeriodTime < 20 And $iPeriodTime >= 2) Then
$sDay = $sDays
EndIf
If ($iPeriodTime >= 20 And (StringRight($iPeriodTime, 1) >= 5) Or StringRight($iPeriodTime, 1) < 1) Or ($iPeriodTime < 20 And $iPeriodTime >= 5) Or $iPeriodTime = 0 Then
$sDay = $s5Days
EndIf
FileWrite($file, "Анализ файлов за период времени." & @CRLF)
FileWrite($file, "Каталог поиска=[" & $sPathFindFile & "]" & @CRLF & "Маска поиска=[" & $sMaskaFile & "]" & @CRLF & "Период=[" & $iPeriodTime & "]" & @CRLF)
ProgressOn("Progress Meter", "Анализ файлов за " & $iPeriodTime & " " & $sDay)
ProgressSet(0, "Построение списка файлов. Подождите ...")
;$aFileDirFind = _FileDirList($sPathFindFile, $sMaskaFile)
$aFileDirFind = _FO_FileSearch($sPathFindFile, $sMaskaFile)
If $aFileDirFind = '' Or $aFileDirFind = 0 Then
FileWrite($file, 'Ошибка при создание списка файлов error=' & @error & @CRLF)
FileClose($file)
Exit
EndIf
ProgressSet(0, " ")
ReDim $aFileDirDate[$aFileDirFind[0] + 1][4]
$aFileDirDate[0][0] = $aFileDirFind[0]
$count_progress_all = $aFileDirFind[0] * 4
For $i = 1 To $aFileDirFind[0]
; Путь к файлу
$aFileDirDate[$i][3] = $aFileDirFind[$i]
; Время создания
$t = FileGetTime($aFileDirFind[$i], 1)
If @error = 1 And $t = 0 Then
$aFileDirDate[$i][0] = ""
FileWrite($file, 'ER-RO-RRRR RR:RR:RR ' & $aFileDirDate[$i][3] & " - ErrorTimeCreate" & @CRLF)
Else
$sTime = $t[0] & '/' & $t[1] & '/' & $t[2] & ' ' & $t[3] & ':' & $t[4] & ':' & $t[5]
$aFileDirDate[$i][0] = _Epoch_encrypt($sTime)
EndIf
; Время модификации
$t = FileGetTime($aFileDirFind[$i], 0)
If @error = 1 And $t = 0 Then
$aFileDirDate[$i][1] = ""
FileWrite($file, 'ER-RO-RRRR RR:RR:RR ' & $aFileDirDate[$i][3] & " - ErrorTimeModif" & @CRLF)
Else
$sTime = $t[0] & '/' & $t[1] & '/' & $t[2] & ' ' & $t[3] & ':' & $t[4] & ':' & $t[5]
$aFileDirDate[$i][1] = _Epoch_encrypt($sTime)
EndIf
; Время последнего доступа
$t = FileGetTime($aFileDirFind[$i], 2)
If @error = 1 And $t = 0 Then
$aFileDirDate[$i][2] = ""
FileWrite($file, 'ER-RO-RRRR RR:RR:RR ' & $aFileDirDate[$i][3] & " - ErrorTimeAcces" & @CRLF)
Else
$sTime = $t[0] & '/' & $t[1] & '/' & $t[2] & ' ' & $t[3] & ':' & $t[4] & ':' & $t[5]
$aFileDirDate[$i][2] = _Epoch_encrypt($sTime)
EndIf
ProgressSet(Ceiling(($count_progress / $count_progress_all) * 100));, Ceiling(($count_progress / $count_progress_all) * 100) & " получение времени файлов")
$count_progress += 1
Next
;_ArrayDisplay($aFileDirDate)
FileWrite($file, @CRLF & '======Список файлов созданных за ' & $iPeriodTime & ' ' & $sDay & '======' & @CRLF & @CRLF)
_ArraySort($aFileDirDate, 1, 1, 0, 0);Сортировка по времени создания
For $i = 1 To $aFileDirDate[0][0]
;Разница в днях
$iDateCalc = ($sCurrentDT_Epo - $aFileDirDate[$i][0]) / $sec_day ;_DateDiff('D', $aFileDirDate[$i][0], $sCurrentDT)
If $iDateCalc <= $iPeriodTime Then
$sAttrib = FileGetAttrib($aFileDirDate[$i][3])
If @error = 1 And $sAttrib = '' Then $sAttrib = 'ERROR'
FileWrite($file, StringRegExpReplace(_Epoch_decrypt($aFileDirDate[$i][0]), '(\d{4})/(\d{2})/(\d{2})', '$3-$2-$1') & " ----" & $sAttrib & "---- " & $aFileDirDate[$i][3] & @CRLF)
EndIf
ProgressSet(Ceiling(($count_progress / $count_progress_all) * 100));, Ceiling(($count_progress / $count_progress_all) * 100) & " проверка времени создания файлов")
$count_progress += 1
Next
FileWrite($file, @CRLF & '======Список файлов измененных за ' & $iPeriodTime & ' ' & $sDay & '======' & @CRLF & @CRLF)
_ArraySort($aFileDirDate, 1, 1, 0, 1);Сортировка по времени модификации
For $i = 1 To $aFileDirDate[0][0]
;Разница в днях
$iDateCalc = ($sCurrentDT_Epo - $aFileDirDate[$i][1]) / $sec_day ;_DateDiff('D', $aFileDirDate[$i][1], $sCurrentDT)
If $iDateCalc <= $iPeriodTime Then
$sAttrib = FileGetAttrib($aFileDirDate[$i][3])
If @error = 1 And $sAttrib = '' Then $sAttrib = 'ERROR'
FileWrite($file, StringRegExpReplace(_Epoch_decrypt($aFileDirDate[$i][1]), '(\d{4})/(\d{2})/(\d{2})', '$3-$2-$1') & " ----" & $sAttrib & "---- " & $aFileDirDate[$i][3] & @CRLF)
EndIf
ProgressSet(Ceiling(($count_progress / $count_progress_all) * 100));, Ceiling(($count_progress / $count_progress_all) * 100) & " проверка времени модификации файлов")
$count_progress += 1
Next
FileWrite($file, @CRLF & '======Список файлов с последним доступом за ' & $iPeriodTime & ' ' & $sDay & '======' & @CRLF & @CRLF)
_ArraySort($aFileDirDate, 1, 1, 0, 2); Сортировка по времени последнего доступа
For $i = 1 To $aFileDirDate[0][0]
;Разница в днях
$iDateCalc = ($sCurrentDT_Epo - $aFileDirDate[$i][2]) / $sec_day ;_DateDiff('D', $aFileDirDate[$i][2], $sCurrentDT)
If $iDateCalc <= $iPeriodTime Then
$sAttrib = FileGetAttrib($aFileDirDate[$i][3])
If @error = 1 And $sAttrib = '' Then $sAttrib = 'ERROR'
FileWrite($file, StringRegExpReplace(_Epoch_decrypt($aFileDirDate[$i][2]), '(\d{4})/(\d{2})/(\d{2})', '$3-$2-$1') & " ----" & $sAttrib & "---- " & $aFileDirDate[$i][3] & @CRLF)
EndIf
ProgressSet(Ceiling(($count_progress / $count_progress_all) * 100));, Ceiling(($count_progress / $count_progress_all) * 100) & " проверка времени последнего доступа к файлам")
$count_progress += 1
Next
FileWrite($file, @CRLF & 'Выполнено за ' & Ceiling(TimerDiff($iTimer) / 1000) & ' сек' & @CRLF)
ProgressSet(100, "Выполнено", "Complete")
Sleep(500)
ProgressOff()
FileClose($file)
If FileExists($MainLog) Then
ShellExecute($MainLog, "", "", "open")
Else
MsgBox(4112, 'Ошибка', "Файл " & $MainLog & " не найден")
EndIf
EndFunc ;==>CreateListFileTime
;func by trancexx
Func _EPOCH_decrypt($epoch_time)
Local $Day2Add = Int($epoch_time / 86400)
Local $iTimeVal = Mod($epoch_time, 86400)
If $iTimeVal < 0 Then
$Day2Add -= 1
$iTimeVal += 86400
EndIf
Local $i_wFactor = Int((573371.75 + $Day2Add) / 36524.25)
Local $i_xFactor = Int($i_wFactor / 4)
Local $i_bFactor = 2442113 + $Day2Add + $i_wFactor - $i_xFactor
Local $i_cFactor = Int(($i_bFactor - 122.1) / 365.25)
Local $i_dFactor = Int(365.25 * $i_cFactor)
Local $i_eFactor = Int(($i_bFactor - $i_dFactor) / 30.6001)
Local $asDatePart[3]
$asDatePart[2] = $i_bFactor - $i_dFactor - Int(30.6001 * $i_eFactor)
;$asDatePart[1] = $i_eFactor - 1 - 12 * ($i_eFactor - 2 >= 13)
$asDatePart[1] = $i_eFactor - 1 - 12 * ($i_eFactor - 2 > 11)
$asDatePart[0] = $i_cFactor - 4716 + ($asDatePart[1] < 3)
Local $asTimePart[3]
$asTimePart[0] = Int($iTimeVal / 3600)
$iTimeVal = Mod($iTimeVal, 3600)
$asTimePart[1] = Int($iTimeVal / 60)
$asTimePart[2] = Mod($iTimeVal, 60)
Return SetError(0, 0, StringFormat("%.2d/%.2d/%.2d %.2d:%.2d:%.2d", $asDatePart[0], $asDatePart[1], $asDatePart[2], $asTimePart[0], $asTimePart[1], $asTimePart[2]))
EndFunc ;==>_EPOCH_decrypt
Func _Epoch_encrypt($date)
Local $main_split = StringSplit($date, " ")
If $main_split[0] - 2 Then
Return SetError(1, 0, "") ; invalid time format
EndIf
Local $asDatePart = StringSplit($main_split[1], "/")
Local $asTimePart = StringSplit($main_split[2], ":")
If $asDatePart[0] - 3 Or $asTimePart[0] - 3 Then
Return SetError(1, 0, "") ; invalid time format
EndIf
If $asDatePart[2] < 3 Then
$asDatePart[2] += 12
$asDatePart[1] -= 1
EndIf
Local $i_aFactor = Int($asDatePart[1] / 100)
Local $i_bFactor = Int($i_aFactor / 4)
Local $i_cFactor = 2 - $i_aFactor + $i_bFactor
Local $i_eFactor = Int(1461 * ($asDatePart[1] + 4716) / 4)
Local $i_fFactor = Int(153 * ($asDatePart[2] + 1) / 5)
Local $aDaysDiff = $i_cFactor + $asDatePart[3] + $i_eFactor + $i_fFactor - 2442112
Local $iTimeDiff = $asTimePart[1] * 3600 + $asTimePart[2] * 60 + $asTimePart[3]
Return SetError(0, 0, $aDaysDiff * 86400 + $iTimeDiff)
EndFunc ;==>_Epoch_encrypt