请教下afan。。。关于ProgressCopy
http://www.autoitx.com/forum.php?mod=viewthread&tid=10098&page=1&fromuid=7644076#pid93521这样改后无法ProgressCopy("D:\", "E:\temp", 1, '', '', '', 1),直接autoit错误 本帖最后由 afan 于 2009-9-30 19:42 编辑
的确没考虑到全盘复制,把那段稍改一下;;;;------------------以下这段为新增部分
If $AddDir = 1 Then
If StringInStr($current, '\') <> 0 Then
$szwjj = StringRegExp($current, '\\([^\\]+)$', 3)
Else
$szwjj = StringRegExp($current, '([^:]+):?', 3)
EndIf
$destination = $destination & $szwjj & "\"
EndIf
;;;;------------------新增结束 我是用 If $Ddir = "" Then $destination = $destination & $Ddir & "\";;;;; 完整代码也贴上好了#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
;ProgressCopy("D:\autoit3", "E:\temp", 1) ;不添加源文件夹例子
ProgressCopy("D:\autoit3", "E:\temp", 1, '', '', '', 1) ;添加源文件夹例子
Func ProgressCopy($current, $destination, $UseMultiColour = 0, $attrib = "-R", $overwrite = 1, $Run1 = 0, $AddDir = 0) ;;;;修改增加$AddDir参数,默认0为不添加源文件夹
;FirstTimeRun Get original DirSize and set up Gui
If $Run1 = 0 Then
Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent, $szwjj
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
$source = $current
If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"
;;;;------------------以下这段为新增部分
If $AddDir = 1 Then
If StringInStr($current, '\') <> 0 Then
$szwjj = StringRegExp($current, '\\([^\\]+)$', 3)
Else
$szwjj = StringRegExp($current, '([^:]+):?', 3)
EndIf
$destination = $destination & $szwjj & "\"
EndIf
;;;;------------------新增结束
If Not FileExists($destination) Then DirCreate($destination); This is why it was failing, the dir did not exist;;;;变更此行代码位置
$tosearch = $current
$Overall = DirGetSize($tosearch, 1)
$OverallQty = $Overall
Global Const $PrCopyGui = GUICreate("进度条", 420, 100, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$Progress0Text = GUICtrlCreateLabel("Please Wait", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)
$progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20)
GUICtrlSetColor(-1, 32250)
$Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 20, $SS_LEFTNOWORDWRAP)
$progressbar2 = GUICtrlCreateProgress(10, 60, 400, 20, $PBS_SMOOTH)
$Progress2Text = GUICtrlCreateLabel("", 10, 82, 400, 20, $SS_LEFTNOWORDWRAP)
GUISetFont(10, 600)
;$Progress2Text2 = GUICtrlCreateLabel("", 150, 62, 400, 20)
GUICtrlSetColor(-1, 32250); not working with Windows XP Style if not using windows classic style or dllcall above
GUISetState(@SW_SHOW)
GUICtrlSetData($Progress1Text, "Working Directory " & $tosearch)
$Run1 = 1
EndIf
$Size = DirGetSize($current, 3)
$Qty = $Size
Local $search = FileFindFirstFile($current & "\*.*")
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
$Qty -= 1
$LocalPercent = 100 - (($Qty / $Size) * 100)
$OverallQty -= 1
$overallpercent = 100 - (($OverallQty / $Overall) * 100)
GUICtrlSetData($Progress0Text, "Total Progress " & Int($overallpercent) & "% completed")
GUICtrlSetData($progressbar1, $overallpercent)
GUICtrlSetData($progressbar2, $LocalPercent)
GUICtrlSetData($Progress2Text, "Copying File " & $file)
If $UseMultiColour Then
GUICtrlSetColor($progressbar2, _ChangeColour($LocalPercent))
GUICtrlSetColor($progressbar1, _ChangeColour($overallpercent))
EndIf
FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $overwrite)
FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
EndIf
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
GUICtrlSetData($Progress1Text, $current & "\" & $file)
ProgressCopy($current & "\" & $file, $destination, $UseMultiColour, $attrib, $overwrite, 1, $AddDir) ;;;;修改增加$AddDir参数
EndIf
WEnd
FileClose($search)
;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
If $overallpercent = 100 Then
GUICtrlSetData($Progress0Text, "Total Progress 100% completed")
GUICtrlSetData($progressbar1, 100)
GUICtrlSetData($progressbar2, 100)
GUICtrlSetData($Progress2Text, "Done!")
Sleep(2000)
GUIDelete($PrCopyGui)
$Run1 = 0
EndIf
EndFunc ;==>ProgressCopy
Func _ChangeColour($start)
$Redness = Int(255 - ($start / 100 * 512))
If $Redness < 0 Then $Redness = 0
$Greeness = Int(($start / 100 * 512) - 257)
If $Greeness < 0 Then $Greeness = 0
$Blueness = Int(255 - ($Redness + $Greeness))
Return ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness
EndFunc ;==>_ChangeColour StringRegExp($current, '([^:]+):?', 3)
学习了 以上改了之后盘符视为一个文件夹,如
ProgressCopy("D:\", "E:\temp", 1, '', '', '', 1)
的结果为复制到 E:\temp\D\ 恩,我知道,所以我没用这个源码,因为若是是disk的话,就不创建文件夹了。。。
If $AddDir = 1 Then ;;;;
If StringInStr($current, '\') <> 0 Then ;;;;判断源目录是否为相对路径
$Ddir = StringRegExp($current, '\\([^\\]+)$', 3) ;;;;
Else;;;;
$Ddir = StringRegExp($current, '.+', 3) ;;;;([^:]+):?
EndIf;;;;
If $Ddir = "" Then $destination = $destination & $Ddir & "\";;;;;
EndIf;;;; 不过,也可以搞作msgbox给用户判断:face (33): 哦,你是这个意思,那直接 ProgressCopy("D:\", "E:\temp", 1) 不就行了吗~ (默认就是不创建文件夹) 额,可是,我修改后,必须是$AddDir = 1,不能为0,因为不想让用户判断 哦,是这样~
那就加个选框吧,让用户决定 曾经想过,但要加的话,版面就难看了,所以没搞 不知道你的软件功能,如果是批量任务那还是使用选框好,不会次次询问,如果是单个任务就无所谓了 当然是单个任务。。。多任务的暂时不想搞
页:
[1]