5i365 (我心飞扬)当前离线
上尉
qixiaobin0715 当前离线
大校
for %%a in (*.txt) do ( set /a n+=1 if not "%%a"=="光年之外1.txt" set "filename=%%a" ) if exist "光年之外1.txt" if %n% equ 2 ren "%filename%" "光年之外2.txt"复制代码
TOP
Nsqs 当前离线
少尉
@echo off set file=光年之外1.txt set new_name=ABC powershell "$s='%file%';$r='%new_name%';$file=dir *.txt;if ($file.count -eq 2 -and (Test-Path $s)){$file|%%{if ($_.name -ne $s){ren $_.FullName ($r+$_.Extension)}}}else{"不存在 '$s',或当前文件夹内不足2个txt文件"}"复制代码
$s='光年之外1.txt' $r='AAA' #指定重命名 $file=dir *.txt if ($file.count -eq 2 -and (Test-Path $s)){ $file|%{ if ($_.name -ne $s){ ren $_.FullName ($r+$_.Extension) } } }else{ "不存在'$s',或当前文件夹内不足2个txt文件" } [System.Console]::ReadKey(0)复制代码
评分人数
flashercs 当前在线
少校
@echo off setlocal enabledelayedexpansion cd /d "%~dp0" REM 需要4个临时文件缓存文件名列表 set oldnames="%temp%\~%random%" set newnames="%temp%\~%random%" set oldexcept="%temp%\~%random%" set newexcept="%temp%\~%random%" >%oldnames% dir /a-d /b *.txt >%newnames% ( echo 光年之外1.txt echo 光年之外2.txt ) >%oldexcept% findstr /ilxvg:%newnames% %oldnames% >%newexcept% findstr /ilxvg:%oldnames% %newnames% echo oldexcept: type %oldexcept% echo newexcept: type %newexcept% <%newexcept% ( for /f "usebackq delims=" %%A in (%oldexcept%) do ( set /p newname= echo ren "%%A" "!newname!" ren "%%A" "!newname!" ) ) del %oldnames% %newnames% %oldexcept% %newexcept% endlocal pause exit /b复制代码