找回密码
 加入
搜索
查看: 2556|回复: 4

[网络通信] robocopy 问题,怎么获得文件数. 文件大小. 文件名(解决)

[复制链接]
发表于 2011-8-11 12:28:38 | 显示全部楼层 |阅读模式
本帖最后由 夜猫猫 于 2011-8-16 11:45 编辑

DOS回显:
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------

  Started : Thu Aug 11 11:59:14 2011

   Source = D:\活佛济公2\
     Dest : G:\活佛济公2\

    Files : *.*
            
  Options : *.* /S /E /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

                          60        D:\活佛济公2\
            Newer                      146.1 m        活佛济公2.24.vcd.rmvb               
  0.0%  0.0%  0.0%  0.1%  0.1%  0.2%  0.2%  0.2%  0.3%  0.3%.............100%  
            New File                   144.2 m        活佛济公2.25.vcd.rmvb  0.0%  0.0%  0.0%  0.1%  0.1%  0.2%  0.2%  0.3%  0.3%  0.3%  0.4%

% 中间很多删了已经能获取百分比,该怎么获取上面数值里的文件数. 文件大小. 文件名代码:

#include <Constants.au3>
#include <GUIConstants.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("测试", 391, 343, 283, 137)
$Pic1 = GUICtrlCreatePic(@ScriptDir&"\1.BMP", 16, 0, 360, 217)
$Label1 = GUICtrlCreateLabel("文件总数:   个", 32, 232, 250, 17)
$Label2 = GUICtrlCreateLabel("剩余文件:   个", 216, 232, 250, 17)
$Label3 = GUICtrlCreateLabel("文件大小:", 32, 256, 80, 17)
$Label4 = GUICtrlCreateLabel("传输速度:    MB/秒", 216, 256, 159, 17)
$Progress1 = GUICtrlCreateProgress(16, 280, 318, 16)
$Label5 = GUICtrlCreateLabel("% ", 340, 282, 25, 17)
$Progress2 = GUICtrlCreateProgress(16, 312, 358, 16)
$Label6 = GUICtrlCreateLabel("", 176, 314, 30, 16)
GUICtrlSetBkColor(-1, -2)
GUICtrlSetFont(-1, 9, 800)
GUICtrlSetColor(-1, 0xff0080)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$sourcedir = "D:\活佛济公2"
$destdir = "G:\活佛济公2"
$ourProcess = Run (@ComSpec & " /c " & 'robocopy.exe ' & $sourcedir & ' ' & $destdir & ' /E', @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
While 1
        If $ourProcess Then
                $charsWaiting = StdoutRead($ourProcess)
                             FileWrite(@ScriptDir& "\1.txt",$charsWaiting)
                If $charsWaiting Then
                        $currentRead = StdoutRead($ourProcess)
                   $percent = StringRegExp($currentRead, '([0-9]{1,3})(?:.[0-9]{1,3})(?:%)',3);获取百分比
         If IsArray($percent) = 1 Then
                        GUICtrlSetData($Progress1 ,$percent[0])
                        GUICtrlSetData($Progress2, $percent[0])
                        GUICtrlSetData($Label5,$percent[0]&"% ")
                        GUICtrlSetData($Label6,$percent[0]&"% ")
            EndIf
                
                EndIf
        EndIf        
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        ProcessClose("robocopy.exe")
                        Exit

        EndSwitch
WEnd

发表于 2011-8-11 13:07:30 | 显示全部楼层
本帖最后由 powerofos 于 2011-8-11 13:09 编辑

提供个别样的方法,调用copy.dll实现的文件复制,但你是使用robocopy.exe,不知道合不合适你。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-8-11 14:40:37 | 显示全部楼层
本帖最后由 夜猫猫 于 2011-8-11 14:42 编辑

用不上
主要是需要知道正在传的文件名是什么。其他就好办。

正则能获取New File                   144.2 m        活佛济公2.25.vcd.rmvb  0.0%这句New File与0.0%之间的数吗?
发表于 2011-8-11 19:06:16 | 显示全部楼层
本帖最后由 powerofos 于 2011-8-11 19:09 编辑

不知道你是怎样的一个复制环境,我很久前用copy.dll试验过,可以随意复制指定某文件夹(内容),当然也能知道正在复制那一个文件,包括文件名。


-----------------------------------------------------------------------------------------------------------------------------------------------


嘿嘿,我翻了一下以前的源码,呵呵,所谓的复制某文件夹下内容是先:  _FileListToArray() 的产物...估计楼主是用不上了
 楼主| 发表于 2011-8-11 22:23:13 | 显示全部楼层
$array = StringRegExp($charsWaiting, 'New File\h{5}(.*?)\h(.*?)\h(.*?)\r\h{2}0.0%6',3)
获取文件名 大小
读TXT能正常显示。但读StdoutRead($ourProcess)但是不能显示。返回数值1

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-2 20:40 , Processed in 0.083408 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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