Показать полную графическую версию : Переименовать файлы по маске и времени создания
В папке D\Inbox есть файлы
v1(1).txt (время создания 00:25)
v1(2).txt (время создания 02:25)
v1(3).txt (время создания 09:25) Цифры в скобках будут каждый день новые.1,2,3 ---т.д.
Необходимо переименовывать только файл v1(2).txt у которого время создания 02:25), остальные файлы переименовываться не должны.
Переименовываться файлы должны по маске v*.* на 2r(имя файла), т.е. было v1(2).txt стало 2rv1(2).txt.
madmasles
18-08-2011, 11:13
porokh,
Попробуйте так:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <File.au3>
$sDir = 'D:\Inbox'
$sHour = '02'
$sMin = '25'
$sPref = '2r'
$iError = 0
$aFiles = _FileListToArray (http://dundats.mvps.org/help/html/libfunctions/_filelisttoarray.htm)($sDir, '*(*).txt', 1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aFiles[0]
$aTimes = FileGetTime (http://www.autoitscript.com/autoit3/docs/functions/FileGetTime.htm)($sDir & '\' & $aFiles[$i], 1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aTimes[3] == $sHour And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) $aTimes[4] == $sMin Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) FileMove (http://www.autoitscript.com/autoit3/docs/functions/FileMove.htm)($sDir & '\' & $aFiles[$i], $sDir & '\' & $sPref & $aFiles[$i], 1) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $iError += 1
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop) ;закомментировать, если переименовывается не один файл
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iError Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(16, 'Error', 'Не переименовано файлов: ' & $iError)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.