Показать полную графическую версию : [решено] При копировании исключить файлы определенного типа
support23
11-06-2014, 13:30
Доброго дня!
Казалось бы простой вопрос, но не могу найти решение: как исключить файлы определенного типа при копировании (например *.zip) ?
madmasles
11-06-2014, 16:50
support23,
Вы покажите код, которым Вы копируете файлы.
support23
12-06-2014, 13:56
Копировать планировал через DirCopy, но у функции отсутствуют необходимый мне параметр
madmasles
12-06-2014, 15:16
support23,
Получайте содержимое папок в массив (несколько вариантов решения), в цикле копируйте файлы (несколько вариантов решения), проверяя их на расширение. Все зависит от конкретной задачи.
support23
14-06-2014, 18:47
вот что получилось в итоге:
#NoTrayIcon
#include <Array.au3>
#Include <FileOperations.au3>
$sPath = "E:\test\source"
if Not FileExists($sPath) then
MsgBox(64, "Ошибка", "Не найден каталог: " & @CRLF & $sPath)
Exit
EndIf
$dPath = "C:\test\destination"
if Not FileExists($dPath) then
DirCreate($dPath)
EndIf
$Level = 5 ; уровень вложенности каталогов
$Exclude = "*.zip|*.7z" ; исключить файлы с расширением zip и 7z
$a1FileList = _FO_FileSearch($sPath, $Exclude, False, 0, 1, 1, 0)
For $i=1 To $a1FileList[0]
FileCopy($a1FileList[$i], $dPath)
Next
$aFolderList = _FO_FolderSearch($sPath, "*", True, $Level, 0, 1, 0)
For $i=1 To $aFolderList[0]
DirCreate($dPath & "\" & $aFolderList[$i])
$a2FileList = _FO_FileSearch($sPath & "\" & $aFolderList[$i], $Exclude, False, 0, 1, 1, 0)
For $j=1 To $a2FileList[0]
FileCopy($a2FileList[$j], $dPath & "\" & $aFolderList[$i])
Next
Next
Exit
madmasles
14-06-2014, 20:22
support23,
Если объем копирования большой, то посмотрите еще здесь: Копируем файлы без "тормозов" (http://autoit-script.ru/index.php/topic,3049.0.html)
support23
15-06-2014, 12:32
спасибо, большой объем как раз я уже и исключил (исключив архивы zip и 7z), вопрос можно считать закрытым.
madmasles
15-06-2014, 13:18
support23,
Еще можно проверять наличие в папке файлов с определенным расширением (если, конечно, в этой папке нет вложенных папок).Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $sDir = @ScriptDir (http://autoit-script.ru/autoit3_docs/macros.htm#@scriptdir) & '\Google_Translator', $sExclude = '*.zip|*.7z', $aExclude, $fExist
$aExclude = StringSplit (http://autoit-script.ru/autoit3_docs/functions/StringSplit.htm)($sExclude, '|')
;~ ...
$fExist = False (http://www.autoitscript.com/autoit3/docs/keywords.htm#False)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aExclude[0]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) FileExists (http://autoit-script.ru/autoit3_docs/functions/FileExists.htm)($sDir & '\' & $aExclude[$i]) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$fExist = True (http://www.autoitscript.com/autoit3/docs/keywords.htm#True)
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
ConsoleWrite (http://autoit-script.ru/autoit3_docs/functions/ConsoleWrite.htm)($sExclude & ' -> ' & $fExist & @LF (http://autoit-script.ru/autoit3_docs/macros.htm#@lf))
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $fExist Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
;~ ... Ваш вариант
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
;~ DirCopy() или по другому
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.