每次运行时,我需要一个代码来重命名一个文件。我做了一个有效的代码,但是它只能用于有限数量的文件。 我希望它对许多文件都有好处(例如,如果要一遍又一遍地执行命令,则不要复制) 这就是我所拥有的。
@ECHO OFF
set /p var1="<"ver.log (Had to use "" because otherwise it is hidden here)
set /a var1=%var1%+1
Echo "%var1%"> "%~dp0\ver.log"
If %var1% EQU 1 (
ren "%~dp0\chrom0.txt" 3.txt
ren "%~dp0\1.txt" chrom0.txt
)
If %var1% EQU 2 (
ren "%~dp0\chrom0.txt" 1.txt
ren "%~dp0\2.txt" chrom0.txt
)
If %var1% EQU 3 (
ren "%~dp0\chrom0.txt" 2.txt
ren "%~dp0\3.txt" chrom0.txt
@Echo "0"> "%~dp0\ver.log"
)
这适用于3个文件。我可以使它工作更多,但是将它用于50个或更多文件是胡说八道。
请帮助。
答案 0 :(得分:0)
我的解决方案:
@echo off
setlocal
pushd "%~dp0"
rem to get "<" on SO type "<"
set /a "var1=0,var2=0"
if exist "%~f0.last" set /p "var1="<"%~f0.last"
:scan
set /a "var1+=1"
if %var1% gtr 500 set /a "var1=0,var2+=1"
if %var2% gtr 2 ( echo Error: not found any file
pause
endlocal
exit /b 2
goto :eof )
if not exist "%var1%.txt" if not exist chrom0.txt goto scan
if exist chrom0.txt if exist "%var1%.txt" ( echo Error: app in use?
pause
endlocal
exit /b 1
goto :eof
) else echo Warning: "%var1%" as chrom0.txt in use
if not exist chrom0.txt ren "%var1%.txt" chrom0.txt
echo "%var1%" in use
echo wait for exit app
rem call "c:\Your\Limited\App.exe" chrom0.txt
pause
ren chrom0.txt "%var1%.txt"
set /p "=%var1%">"%~f0.last" <nul
rem work in loop
if exist "%~f0.loop" goto scan
popd
endlocal
exit /b 0
答案 1 :(得分:0)
谢谢大家。我用了你的技巧,并最终得到了这个脚本。 :开始
set / p var1 =
如果%var1%gtr 4设置为/ a“ var1 = 1”
ren“%〜dp0chrom0.txt”%var1%.txt
set / a var2 =%var1%+ 1
如果%var2%gtr 5设置为/ a“ var2 = 1”
回声“%var2%”>“%〜dp0log.log”
ren“%〜dp0%var2%.txt” chrom0.txt