带有文件名和计数的微调器
Spinner with file names and count
我正在尝试编辑此代码以显示微调器、文件名和移动的文件总数,每移动一百个文件就会更新一次。我已经解决了微调器部分,但我无法获取文件名和准确计数。在这种情况下,我有 3,554 个文件,但它停在 3,500 个。我想将它集成到另一组实际执行文件移动的代码中。来自 Magoo 的代码列在 post 的末尾。非常感谢任何帮助。
旋转器代码
@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%\
好吧,我想承诺就是承诺。 :)
好的。无论您是否意识到,您将遇到的部分困难是将 Backspace 捕获到变量并将其 set /P
ing 到控制台仅将光标向后移动一列。它不会用空白 space 替换字符。因此,如果您要回显文件名,那么如果 filename.ext
比之前的 filename.ext
.
短,那么 set /P "=filename.ext"
会留下一些不愉快的显示
您可能 set /P "= %BS%%BS%" to overwrite each character with a space, but doing this with a
for /L` 循环会导致线路闪烁,同样令人不快。
所以我的解决办法是把128回space抓到一个变量,然后用数字子串提取到set /P "=%BS:~-num%"
来消除闪烁。如果当前行比上一行短,我还会在行尾 space 填充然后重新返回 space 。最后,我将行的长度限制为 80 个字符以避免换行(从中无法恢复任何数量的程序退格)。
对于我的测试,我只是使用 C:
驱动器的内容作为要循环的文件列表。如果您在集成 Magoo 的 :process
代码时需要帮助,请发表评论,我会在有机会时帮助您。不过今晚我得坐飞机。现在,将其保存并 运行 作为概念证明。这只是一场激光表演。它在当前状态下实际上并没有移动任何东西。
@ECHO OFF
SETLOCAL
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 /R "C:\" %%I in (*) do (
set /a filesMoved += 1
call :spinner !filesMoved! "%%~nxI"
)
call :spinner %filesMoved% Done.
endlocal & echo;
goto :EOF
:spinner <filecount> <filename>
set /a spinPos += 1, spinPos %%= 4, hundred = %~1 / 100 * 100
if "%~2"=="Done." set hundred=%~1
set "str=[!spinChars:~%spinPos%,1!] %hundred% 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
goto :EOF
: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%"
goto :EOF
我正在尝试编辑此代码以显示微调器、文件名和移动的文件总数,每移动一百个文件就会更新一次。我已经解决了微调器部分,但我无法获取文件名和准确计数。在这种情况下,我有 3,554 个文件,但它停在 3,500 个。我想将它集成到另一组实际执行文件移动的代码中。来自 Magoo 的代码列在 post 的末尾。非常感谢任何帮助。
旋转器代码
@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%\
好吧,我想承诺就是承诺。 :)
好的。无论您是否意识到,您将遇到的部分困难是将 Backspace 捕获到变量并将其 set /P
ing 到控制台仅将光标向后移动一列。它不会用空白 space 替换字符。因此,如果您要回显文件名,那么如果 filename.ext
比之前的 filename.ext
.
set /P "=filename.ext"
会留下一些不愉快的显示
您可能 set /P "= %BS%%BS%" to overwrite each character with a space, but doing this with a
for /L` 循环会导致线路闪烁,同样令人不快。
所以我的解决办法是把128回space抓到一个变量,然后用数字子串提取到set /P "=%BS:~-num%"
来消除闪烁。如果当前行比上一行短,我还会在行尾 space 填充然后重新返回 space 。最后,我将行的长度限制为 80 个字符以避免换行(从中无法恢复任何数量的程序退格)。
对于我的测试,我只是使用 C:
驱动器的内容作为要循环的文件列表。如果您在集成 Magoo 的 :process
代码时需要帮助,请发表评论,我会在有机会时帮助您。不过今晚我得坐飞机。现在,将其保存并 运行 作为概念证明。这只是一场激光表演。它在当前状态下实际上并没有移动任何东西。
@ECHO OFF
SETLOCAL
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 /R "C:\" %%I in (*) do (
set /a filesMoved += 1
call :spinner !filesMoved! "%%~nxI"
)
call :spinner %filesMoved% Done.
endlocal & echo;
goto :EOF
:spinner <filecount> <filename>
set /a spinPos += 1, spinPos %%= 4, hundred = %~1 / 100 * 100
if "%~2"=="Done." set hundred=%~1
set "str=[!spinChars:~%spinPos%,1!] %hundred% 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
goto :EOF
: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%"
goto :EOF