1
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.

バッチファイルでdirname

Last updated at Posted at 2019-08-04

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

ソース

dirname.bat
@echo off

call :dirname C:\hoge\fuga.csv
echo dirname1:%dirname%

call :dirname C:\hoge\fuga\piyo.csv
echo dirname2:%dirname%

exit /b

:dirname

	setlocal
	endlocal & set dirname=%~dp1

exit /b

実行結果

>dirname.bat
dirname1:C:\hoge\
dirname2:C:\hoge\fuga\

解説

バッチパラメータの%~dp1を利用して渡されたパラメータからドライブ文字とファイル名以外のパスだけを取り出すことで実現しています。

関連記事

バッチファイルでbasename

1
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
1
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?