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?

More than 5 years have passed since last update.

ファイルのフルパスを渡して、そのファイル名だけを取得するbasename処理をバッチファイルで作ってみます。

ソース

basename.bat
@echo off

call :basename C:\hoge\fuga.csv
echo basename1:%basename%

call :basename C:\hoge\fuga\piyo.csv
echo basename2:%basename%

exit /b

:basename

	setlocal
	endlocal & set basename=%~nx1

exit /b

実行結果

>basename.bat
basename1:fuga.csv
basename2:piyo.csv

解説

バッチパラメータの%~nx1を利用して渡されたパラメータからファイル名と拡張子だけを取り出すことで実現しています。

関連記事

バッチファイルでdirname

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?