本帖最后由 kzpichuli 于 2015-5-8 20:07 编辑
- @echo off
- mode con cols=70 lines=15
- title ★本命令复制文件和文件夹★
- setlocal enabledelayedexpansion
- ::=================================主程序1=================================
- :pk
- cls
- echo.
- echo.
- echo.
- echo ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
- echo ▕本命令复制文件和文件夹,速度快,重复的跳过▏
- echo ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- echo.
- echo.
- echo 说明:某些系统需要把程序放到桌面上才能运行
- echo.
- set yes=3
- set yes2=0
- echo ★第一步★指定要复制的文件或者文件夹
- echo.
- set/p "file1=→→拖入要复制的文件夹:"
- if not defined file1 goto :pk
- set "pppp1=%file1:"=%"
- if "%pppp1%" equ " " goto :pk
- set "pppp1=%pppp1:&=^&%"
- set "file1="%pppp1%""
- echo.
- echo.
- if not exist %file1% goto :pk
- pushd %file1% 2>nul&&set yes=1||set yes=0
- popd
- if %yes% equ 1 (
- echo ■要复制的为■:文件夹-%file1%
- )
- if %yes% equ 0 (
- echo ■要复制的为■:文件-%file1%
- )
-
-
-
- ::=================================主程序2=================================
- :ak2
- echo.
- echo.
- echo ★第二步★指定要复制到哪里?
- echo.
- set/p "file2=→→拖入复制到何处:"
- set "pppp2=%file2:"=%"
- set "pppp2=%pppp2:&=^&%"
- set "file2="%pppp2%""
- pushd %file2% 2>nul&&set yes2=1
- popd
- if %yes2% equ 0 echo 错误 &goto :ak2
- ::=================================主程序3=================================
- cls
- echo.
- echo 稍后,正在初始化……
-
- if %yes% equ 0 goto :bu2
- call :panduan
- start /min /i cmd /c "(robocopy /e /ns /nc "%pppp1%" "%pppp2%" )"
- call :jindutiao
- echo 完成!&pause>nul
- exit
-
-
- :bu2
- set "route=%file1:"=%"
- call :fenli
- md "%route%\%filenamek%"
- move %file1% "%route%\%filenamek%"
- set "pppp=%route%\%filenamek%"
- set "pppp=%pppp:&=^&%"
- call :panduan
- start /min /i cmd /c "(robocopy /e /ns /nc "%pppp%" "%pppp2%" )"
- call :jindutiao
- move "%route%\%filenamek%\%filename%" "%route%" 2>nul
- rd "%route%\%filenamek%" 2>nul
- echo 完成!&pause>nul
- exit
- goto :eof
-
- ::=================================路径提取名字和路径的程序=================================
- :fenli
- set filenamek=
- set filename=
- :separate2
- if not "%route:~-1%"=="\" (
- set "filenamek=%route:~-1%%filenamek%"
- set "route=%route:~0,-1%"
- goto separate2
- )
- set "route=%route:~0,-1%"
- set "filename=%filenamek%"
- set "filenamek=%filenamek:~0,-4%"
- goto :eof
-
-
-
- ::=================================判断robocopy程序=================================
- :panduan
- set /a numh=0
- set hand_0=0
- set hand_1=0
- set hand_2=0
- for /f "tokens=1,2* delims==" %%i in ('wmic process where name^="robocopy.exe" get Handle /value 2^>nul^|findstr "Handle" ') do (
- set /a numh+=1
- set hand_!numh!=%%j
- ) 2>nul
- goto :eof
-
- ::=================================进度条程序1-获取当前程序句柄=================================
- :jindutiao
- set hand=0
- for /f "tokens=1,2* delims==" %%i in ('wmic process where name^="robocopy.exe" get Handle /value 2^>nul^|findstr "Handle" ') do (
- if %%j neq %hand_0% (
- if %%j neq %hand_1% (
- if %%j neq %hand_2% (
- set hand=%%j
- goto:out3
- )
- )
- )
- )
- :out3
- if %hand% equ 0 (cls&echo.&echo.&echo 警告!robocopy命令没有启动!任意键退出程序!&pause&goto :eof)
-
-
- ::=================================进度条程序2-初始化程序=================================
- mode con cols=60 lines=10
- color 1f
- set jindu=
- set daxiao=0000000
- set /a jindu1=0
- for /f "tokens=3" %%i in ('dir /a /s /-c %file1%^|findstr "个文件"') do (set daxiao2=%%i )
- set /a all=%daxiao2:~0,-6%
- set daxiao=
-
- :begain2
- set daxiao=00
- set jindu=
- for /f "tokens=1,2* delims==" %%i in ('wmic process where Handle^="%hand%" get WriteTransferCount /value 2^>nul^|findstr "WriteTransferCount"') do (
- set daxiao=%%j
- goto :outp
- ) 2>nul
- :outp
- if "%daxiao%" equ "00" (
- if %yes% equ 0 (
- move "%route%\%filenamek%\%filename%" "%route%"
- rd "%route%\%filenamek%"
- )
- echo 警告!robocopy命令已经关闭!是否已完成!
- pause>nul
- goto :eof
- )
-
-
- call :jisuan
-
-
- ::=================================进度条程序2-显示程序=================================
-
- for /l %%i in (0 5 %jindu1%) do (
- set "jindu=!jindu!▉"
- )
- title 进度:%jindu1%﹪
- cls
- echo Robocopy复制进度
- ECHO.
- echo 容量进度(M): %daxiao:~0,-1% / %all:~0,-1%
- echo.
- echo 百分进度:%jindu1%﹪
- echo ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
- echo %jindu%
- echo ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- if %jindu1% gtr 95 color 4E
- timeout /t 1 1>nul
-
-
- if %jindu1% equ 100 (title 警告!&goto :eof)
- goto :begain2
- goto :eof
-
-
-
- ::=================================进度条程序3-计算进度程序=================================
- :jisuan
- set num=
- set dec_str=
- set /a daxiao=%daxiao:~0,-7%
- if "%daxiao%" equ "" set daxiao=1
- set input=%daxiao% %all% 2
- for /f "delims=" %%i in ("%input%") do call :count %%i
- goto :eof
-
-
- :count
- set /a int_str=%1/%2
- set /a mod=%1%%%2
- if %mod% equ 0 goto :hao
- :count_dec
- set mod=%mod%0
- if %mod% lss %2 (
- set dec_str=!dec_str!0
- goto count_dec
- ) else (
- set /a dec=%mod%/%2
- set dec_str=!dec_str!!dec!
- set /a mod=%mod%%%%2
- )
- set /a num+=1
- if %mod% neq 0 if %num% lss 2 goto count_dec
- :hao
- if %int_str% geq 1 (set /a jindu1=100 &goto :eof)
- if "!dec_str:~0,1!" equ "0" (
- if "!dec_str:~1,1!" equ "0" (set /a jindu1=1 &goto:eof)
- set /a jindu1=!dec_str:~1,1!
- )
- set /a jindu1=!dec_str:~0,2!
- goto :eof
-
复制代码 朋友们好!
先简单的介绍下制作过程:公司经常处理文件,我嫌系统本身copy太慢,robocopy真的很棒,有时候copy速度达到200m/s,系统本身根本无法做到!希望高手完善,因为我是才接触批,我的知识已经封顶了!
但是复制大数据比如100g,看不见总体进度,总是不舒服,
一开始利用每秒dir出粘贴处的文件夹容量来计算,后来发现这样慢,而且存在一个很大的问题:比如复制一个10g的大文件,刚复制%1,粘贴处的文件就变成10g了,所以这样计算非常不准
后来想利用robocopy自带的输出文件百分比,一点一点的计算,发现不现实,偶然发现可以利用wmic命令找到robocopy的实时读取和写入数据容量,有了这个就可以准确地知道robocopy当前复制了多少数据,
所以就制作出来了,在网上查了很久,在这里也逛达很久,也许大家不需要这个功能,但是看到有朋友在问,所以我就拿出共同研究,希望有高手能将这个功能完善!
目前,我经常用该命令,发现一些现实问题:
1.进度条的问题
进度条无法到达100%,因为99%时,robocopy已经退出,
多个robocopy同时复制,存在错误
发现复制的过程中进度条有时候一闪,知道是计算数据出现错误,但是一闪而过,也不知道为什么
2.非要放在桌面才能运行
3。界面难看
4.设置的是拖入复制和粘贴目录,但是非要点击确定键
5.不知道为什么试验多次,进度非常准确,就是无法计算出复制速度和预计时间,这是我最纳闷的地方
需要robocopy加精准进度的朋友请你们拿回去研究,我太累了,知识太有限!研究好了,别忘了共享下!谢谢! |