0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【bat】ファイルのリネーム

Last updated at Posted at 2025-06-27

以前に書いたarray.batを用いたリネームツール

1.クリップボードにリネーム後のファイルネームの文字列(複数行)をコピー
2.リネームするファイルを選択し、このbatにD&D
3.undo、元に戻すときは『y』

【注意】
コピーした行数が、ファイル数より少ないとスルーされる
D&Dで掴んだファイルが一番目になる

@echo off
call %~dp0array.bat init
echo.

%ARRAY% array BEFORE %*
for /f "usebackq tokens=*" %%a in (`powershell get-clipboard`) do %ARRAY% shove AFTER "%%~a"

if %BEFORE.size% gtr %AFTER.size% (
	echo less new name
	goto :end
)

call :forSome RENAME BEFORE AFTER

echo.
echo # undo rename ?
echo.
:chooser2
choice /c yn
if %errorlevel% == 1 (
	echo ### start undo
	echo.
	call :forSome UNDO BEFORE AFTER
) else if %errorlevel% == 2 (
	goto :end
) else (
	echo miss [%errorlevel%]
	goto :chooser2
)
goto :end

:UNDO
echo %2
ren "%~dp2%~3%~x2" "%~nx2"
exit /b

:RENAME
if "%~2" == "empty" (
	echo @@@ empty
	exit /b
)
echo %2	%~dp2%~3%~x2
ren %2 "%~3%~x2"
exit /b

:forSome
set array.args=%*
call set array.args=%%array.args:*%~1 =%%
for /f "usebackq delims=	 tokens=*" %%a in (`%ARRAY% viewSome %array.args%`) do call :%~1 %%~a
exit /b

:end
pause
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?