我有一个很久以前在某个地方找到的微调器的代码。我正在试图找出如何修改它,以便显示每移动1000个文件的更新。所以,它看起来像这样:
Moving XML Files...| 1,000 Files moved
Moving XML Files.../ 2,000 Files moved
Moving XML Files...- 3,000 Files moved
Moving XML Files...\ 4,000 Files moved
旋转器字符继续移动的位置。我将在接近一百万个文件上运行它,所以我真的需要指出状态是什么。非常感谢任何有关更好方法的帮助或建议。
CODE
@echo off
setlocal
Call :SpinnerEx
exit /b
:SpinnerEx
setlocal EnableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
FOR /L %%n in (1,1,50) DO (
call :spinner
ping localhost -n 1 > nul
)
exit /b
:spinner
set /a "spinner=(spinner + 1) %% 4"
set "spinChars=\|/-"
<nul set /p ".=Moving XML Files...!spinChars:~%spinner%,1!!CR!"
exit /b
HERE是实际执行Magoo提供的移动的代码
答案 0 :(得分:1)
以Magoo的脚本为基础,我将替换
) DO SET "filename=%%a"&CALL :process
与
) DO (
SET "filename=%%a"&CALL :process
rem increment file counter
rem if total divided by 1000 has no remainder, advance the spinner
)
这样的事情:
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir\t w o"
SET "spinChars=\|/-"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
SET "filesmoved=0"
PUSHD "%sourcedir%"
set /P "=Moving XML Files...%spinChars:~0,1% 0 Files moved"<NUL
FOR /f "tokens=1*delims=" %%a IN (
'dir /b /a-d "%sourcedir%\*_*_*.xml" '
) DO (
SET "filename=%%a"&CALL :process
set /a filesmoved += 1, thousand = filesmoved %% 1000
setlocal enabledelayedexpansion
if !thousand! equ 0 call :spinner
endlocal
)
POPD
GOTO :EOF
:process
FOR /f "tokens=2,3,6delims=_" %%m IN ("%filename%") DO SET "date1=%%m"&SET "date2=%%n"&SET "whichdate=%%o"
IF DEFINED whichdate SET "date1=%date2%"
IF NOT DEFINED date2 GOTO :eof
ECHO(MD .\%date1:~0,4%\%date1:~4,2%
ECHO(MOVE "%filename%" .\%date1:~0,4%\%date1:~4,2%\
GOTO :EOF
:spinner
set "moved=%filesmoved%"
:spinner2
if %filesmoved% geq 4000 set /a filesmoved -= 4000 & goto :spinner2
set /a spinpos = filesmoved / 1000
for /L %%I in (1,1,50) do set /P "=%BS%"<NUL
set /P "=Moving XML Files...!spinChars:~%spinPos%,1! %moved% Files moved"<NUL
goto :EOF
for /f... ("prompt $H...")
行将退格字符捕获到变量(%BS%
)。 for /L %%I in (1,1,50)
行退格50次。希望其余的都是不言自明的。
如果您想在不实际移动任何文件的情况下测试逻辑,请使用简单的for /L
循环替换文件迭代循环的相同脚本:
@ECHO OFF
SETLOCAL
SET "spinChars=\|/-"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
SET "filesmoved=0"
set /P "=Moving XML Files...%spinChars:~0,1% 0 Files moved"<NUL
for /L %%I in (1,1,50000) do (
set /a filesmoved += 1, thousand = filesmoved %% 1000
setlocal enabledelayedexpansion
if !thousand! equ 0 call :spinner
endlocal
)
goto :EOF
:spinner
set "moved=%filesmoved%"
:spinner2
if %filesmoved% geq 4000 set /a filesmoved -= 4000 & goto :spinner2
set /a spinpos = filesmoved / 1000
for /L %%I in (1,1,50) do set /P "=%BS%"<NUL
set /P "=Moving XML Files...!spinChars:~%spinPos%,1! %moved% Files moved"<NUL
goto :EOF