我正在尝试编辑此代码以显示微调器,移动的每100个文件更新的文件名和移动的文件总数。我有旋转器部分,但我不知道文件名和准确计数。在这种情况下,我有3,554个文件,但它停在3,500。我想将它集成到另一组实际上移动文件的代码中。来自Magoo的代码列在帖子的末尾。任何帮助非常感谢。
Spinner代码
@ECHO OFF
SETLOCAL
SET "sourcedir=C:\temp\xmls"
SET "spinChars=\|/-"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
SET "filesmoved=0"
PUSHD "%sourcedir%"
For %%A in (*.xml) do set /a cnt+=1
Echo %cnt% files.
For /L %%I in (1,1,%cnt%) do (
set /a filesmoved += 1, hundred = filesmoved %% 100
setlocal enabledelayedexpansion
if !hundred! equ 0 call :spinner
endlocal
)
goto :EOF
:spinner
set "moved=%filesmoved%"
:spinner2
if %filesmoved% geq 400 set /a filesmoved -= 400 & goto :spinner2
set /a spinpos = filesmoved / 100
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
批量移动XML文件
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir\t w o"
PUSHD "%sourcedir%"
FOR /f "tokens=1*delims=" %%a IN (
'dir /b /a-d "%sourcedir%\*_*_*.xml" '
) DO SET "filename=%%a"&CALL :process
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
最新代码
@ECHO OFF
SETLOCAL
Title Reorganizing XMLs - DO NOT CLOSE THIS WINDOW!
mode con: cols=100 lines=6
set "sourcedir=C:\Temp\XMLs"
pushd %sourcedir%
SET "spinChars=\|/-"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
set "spaces= "
SET /a filesMoved = 0, spinPos = 0, prev = 0
echo Moving XML Files...
setlocal enabledelayedexpansion
for /L %%I in (1,1,7) do set "BS=!BS!!BS!"
for /L %%I in (1,1,3) do set "spaces=!spaces!!spaces!"
For %%A in (*.xml) do set /a cnt+=1
echo.
Echo %cnt% files.
echo.
FOR /f "tokens=1*delims=" %%a IN ('dir /b /a-d "%sourcedir%\*.xml" ' ) DO (
set /a filesmoved += 1
call :spinner !filesmoved! "%%~nxa"
)
call :spinner %filesMoved% Done.
endlocal & echo;
exit /b 0
:spinner <filecount> <filename>
set /a spinPos += 1, spinPos %%= 4, ten = %~1 / 10 * 10
if "%~2"=="Done." set ten=%~1
set "str=[!spinChars:~%spinPos%,1!] %ten% files moved... [%~2]"
set "str=%str:~0,79%"
call :length len "%str%"
set /a diff = 79 - len
if %diff% gtr 0 set "str=%str%!spaces:~-%diff%!"
set /P "=!BS:~-79!%str%"<NUL
if "%~2" NEQ "Done." call :process %~2
exit /b 0
:length <return_var> <string>
setlocal enabledelayedexpansion
if "%~2"=="" (set ret=0) else set ret=1
set "tmpstr=%~2"
for %%I in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if not "!tmpstr:~%%I,1!"=="" (
set /a ret += %%I
set "tmpstr=!tmpstr:~%%I!"
)
)
endlocal & set "%~1=%ret%"
exit /b 0
:process
FOR /f "tokens=2,3,6delims=_" %%m IN ("%~1") DO SET "date1=%%m"&SET "date2=%%n"&SET "whichdate=%%o"
IF DEFINED whichdate SET "date1=%date2%"
IF NOT DEFINED date2 exit /b 1
If not exist .\%date1:~0,4%\%date1:~4,2% MD .\%date1:~0,4%\%date1:~4,2%
MOVE %~1 .\%date1:~0,4%\%date1:~4,2%\
答案 0 :(得分:1)
嗯,承诺是我猜的承诺。 :)
行。无论你是否意识到,你遇到的部分困难是将 Backspace 捕获到一个变量中,set /P
将它移动到控制台只会将光标移回一列。它不会用空格替换字符。因此,如果您要回显文件名,那么如果set /P "=filename.ext"
比之前的filename.ext
短,那么退回filename.ext
会显示一些不愉快。
你可以{/ 1}} / L`循环会导致线条闪烁,也令人不快。
所以我的解决方案是将128个退格捕获到一个变量,然后使用数字子串提取到set /P "= %BS%%BS%" to overwrite each character with a space, but doing this with a
来消除闪烁。如果当前行比前一行短,我也会在行尾填充空格然后重新退格。最后,我将行的长度限制为80个字符,以避免换行(从中无法恢复任何程序化的退格)。
对于我的测试,我只是使用我的set /P "=%BS:~-num%"
驱动器的内容来循环访问文件列表。如果您需要帮助整合Magoo的C:
代码,请发表评论,我会在有机会时帮助您。不过,我今晚必须乘坐喷气式飞机。现在,保存它并将其作为概念证明运行。这只是激光表演。它实际上并没有在当前状态下移动任何东西。
:process