2
4

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.

バッチファイルを作るときに見た・考えたことメモ

Posted at

全体

開発に役立つ,BATファイルの書き方・パターン集 (コマンドプロンプトの定石を体系的に学び,バッチ中級者になろう) - 主に言語とシステム開発に関して

サブルーチン

  • ローカル変数を有効にする。
  • 戻り値は return など決まった変数で返す。

call :sub
set ret=%return%

:sub
setlocal
:: サブルーチンの中身
endlocal & set return=%return%
exit /b

参考

バッチファイルで、setlocal~endlocal内での変数の値を外部に引き継ぎたい!IIJIMASの日記

ファイルパスから拡張子を取り出す

パスの加工は(変数ではなく)引数で行う(?)ので、一旦サブルーチンに飛ばす。

call :get_extension hogehoge.ext
echo %return% 
exit /b

:get_extension
set return=%~x1
set return=%return:~1%
exit /b

参考

バッチファイルでファイルパスからファイル名や拡張子を自由に取り出す方法 - みちしるべ -
BATファイルで文字列の切り出し

IF の比較演算子

If - DOS コマンド一覧

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?