DirectoryExists.bat
Windowsのバッチファイルで、任意のファイルパスにフォルダが存在するかを判定するプログラムです。仕様はプログラム中のコメントに記載しています。
実行に必要なバッチファイル(GitHub)
処理抜粋
判定部分を抜粋しています。
ライブラリとして作ったプログラムなので、フォルダ以外は除外する実装になっています。
set FILE_PATH=ファイルパス(フォルダ) rem フォルダが存在しない場合、1を返す if not exist %FILE_PATH%\ ( endlocal exit /b 1 ) rem 以降はファイルパスにフォルダが存在する
実行形式
call DirectoryExists.bat ファイルパス
指定したファイルパスにフォルダが存在するか判定をします。
実行例と戻り値
call C:¥directory ... 存在する 戻り値 0 call C:¥file.txt ... 存在するがファイル 戻り値 1 call "C:¥not found" ... 存在しない 戻り値 1
DirectoryExists.bat
@setlocal @echo off rem ****************************************************************** rem * DirectoryExists.bat: 指定されたパスがフォルダであるか検証する rem * rem * [説明] rem * <戻り値> rem * ・フォルダの場合、0を返す rem * ・フォルダ以外の場合、1を返す rem * rem * [引数] rem * %1: フォルダパス rem * rem * [バージョン] rem * 1.0.0 rem ****************************************************************** rem echo DirectoryExists.bat %1 set FILE_PATH=%1 rem NULLの場合、1を返す if not defined FILE_PATH ( endlocal exit /b 1 ) rem フォルダが存在しない場合、1を返す if not exist %FILE_PATH%\ ( endlocal exit /b 1 ) endlocal exit /b 0