找回密码
 加入
搜索
查看: 10416|回复: 25

复制文件夹的问题!

  [复制链接]
发表于 2008-5-5 20:11:35 | 显示全部楼层 |阅读模式
DirCopy("C:\Program Files\Tencent\QQ2008", "d:\QQ2008", 1)
我需要带上进度条,应该怎么做?

[ 本帖最后由 浅绿 于 2008-5-11 09:59 编辑 ]
发表于 2008-5-5 21:51:21 | 显示全部楼层
呃.这个我也想知道..如果不判断文件数量就很容易了..事先做个进度条出来到时候调用就行了...
DirCopy 这函数拷贝文件....那速度不是一般人能忍受的..
 楼主| 发表于 2008-5-5 21:55:10 | 显示全部楼层
我在学校的计算机上保留着一个函数集?是叫函数集?不知道在什么地方下载的,说用那个函数集可以复制文件带上进度条,不过不会使用。。

DirCopy 这函数拷贝文件....那速度不是一般人能忍受的..
难道 考文件夹还有其它命令吗?
发表于 2008-5-5 22:27:55 | 显示全部楼层
帮助中的例子:

ProgressOn("Progress Meter", "Increments every second", "0 percent")
For $i = 10 to 100 step 10
        sleep(1000)
        ProgressSet( $i, $i & " percent")
Next
ProgressSet(100 , "Done", "Complete")
sleep(500)
ProgressOff()

根据 目标文件夹的大小/总文件的大小
发表于 2008-5-5 22:54:44 | 显示全部楼层

回复 1# 浅绿 的帖子

顶一下吧!!!!!!
 楼主| 发表于 2008-5-6 21:34:08 | 显示全部楼层
举例。。举例。。谢谢。
发表于 2008-5-7 13:55:09 | 显示全部楼层
#include <GUIConstants.au3>
ProgressCopy("D:\Images", "e:\Backup\",1);要复制的文件

Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "-R", $overwrite = 1 ,$Run1 = 0 )

;FirstTimeRun Get original DirSize and set up Gui
If $Run1 = 0 Then
Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist
$source = $current
If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"
$tosearch = $current
$Overall = DirGetSize($tosearch, 1)
$OverallQty = $Overall[1]
Global Const $PrCopyGui = GUICreate("Copying Files", 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[1]
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[1]) * 100)
$OverallQty -= 1
$overallpercent = 100 - (($OverallQty / $Overall[1]) * 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)
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

评分

参与人数 1金钱 +10 收起 理由
Amu + 10 鸟东的马甲?不错不错!

查看全部评分

发表于 2008-5-7 14:10:24 | 显示全部楼层
原帖由 马甲 于 2008-5-7 13:55 发表
#include
ProgressCopy("D:\Images", "e:\Backup\",1);要复制的文件

Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "-R", $overwrite = 1 ,$Run1 = 0 )

;FirstTimeRun Get origi ...


请注明使用编译版本,3.2.9.3.1运行出错。

[ 本帖最后由 华杰 于 2008-5-7 14:23 编辑 ]
发表于 2008-5-7 14:33:02 | 显示全部楼层
原帖由 马甲 于 2008-5-7 13:55 发表
#include
ProgressCopy("D:\Images", "e:\Backup\",1);要复制的文件

Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "-R", $overwrite = 1 ,$Run1 = 0 )

;FirstTimeRun Get origi ...

我用3.2.5.5.1版本运行的时候没错...这代码好哇
发表于 2008-5-7 15:43:14 | 显示全部楼层
不知道楼主要的什么效果?
提供一个供参考:
_FileCopy('d:\autoit3','d:\aaa');注意,此处路径必须确实存在

Func _FileCopy($fromFile,$tofile)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 16
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_SIMPLEPROGRESS)
EndFunc

关于参数$FOF_SIMPLEPROGRESS
#cs
Folder.CopyHere(vItem [, vOptions])
Parameters

vItem Required. The item or items to copy. This can be a string that represents a file name, a FolderItem object, or a FolderItems object.
vOptions Optional. Options for the copy operation. This value can be zero or a combination of the following values. These values are based upon flags defined for use with the fFlags member of the C++ SHFILEOPSTRUCT structure. These flags are not defined as such for Microsoft Visual Basic, Visual Basic Scripting Edition (VBScript), or Microsoft JScript, so you must define them yourself or use their numeric equivalents.4 Do not display a progress dialog box.  
8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.  
16 Respond with "Yes to All" for any dialog box that is displayed.  
64 Preserve undo information, if possible.
128 Perform the operation on files only if a wildcard file name (*.*) is specified.  
256 Display a progress dialog box but do not show the file names.  
512 Do not confirm the creation of a new directory if the operation requires one to be created.  
1024 Do not display a user interface if an error occurs.  
2048 Version 4.71. Do not copy the security attributes of the file.
4096 Only operate in the local directory. Don't operate recursively into subdirectories.
9182 Version 5.0. Do not copy connected files as a group. Only copy the specified files.  
http://msdn2.microsoft.com/en-us/library/ms630707.aspx
#ce

评分

参与人数 1金钱 +10 收起 理由
Amu + 10 这个赞啊!

查看全部评分

 楼主| 发表于 2008-5-10 21:05:11 | 显示全部楼层
谢谢各位。
pcbar版主的这个可以使用。我想要ProgressSet(100 , "Done", "Complete")这种类型的。

马甲发的那段代码,我用我们论坛上的Autoit2.11.1运行的时候提示出错,即便把那些都声明了,还是不行,能不能优化一下适合论坛版本使用的?
发表于 2008-5-10 21:39:59 | 显示全部楼层
如果你没有打错字,Autoit2.11.1相信是没有几个人会将以上脚本改到可以运行的了。

还有10楼的例子,相信应该是最简单的了。直接调用系统的。非常好用。
 楼主| 发表于 2008-5-10 22:00:51 | 显示全部楼层
--_--#!
就你眼睛好使。。
打错字啦。。我现在安装的是3.2.11.1.1
发表于 2008-5-10 22:21:31 | 显示全部楼层
如果你的真的看上边的不明白。用10楼的例子吧。
发表于 2008-5-13 13:16:15 | 显示全部楼层
我用FileInstall编写脚本打包成exe文件,要怎么编写加入显示进度呢?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-17 03:28 , Processed in 0.077429 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表