このエントリーをはてなブックマークに追加


フォルダの存在チェックを行う・FolderExists

FileSystemObjectのFolderExistsメソッドを使用することにより、フォルダ(ディレクトリ)の存在チェックをすることができます。
以下にFolderExistsメソッドを使用したVBScriptサンプルコードおよびサンプルコードの実行結果を記します。


関連記事

フォルダ(ディレクトリ)の存在チェックを行うVBScriptサンプルコードと実行結果

以下に、ファイルの存在チェックを行うVBScriptサンプルコードと実行結果を記します。

VBScriptサンプルコード

Set fso = CreateObject("Scripting.FileSystemObject")
' Create Folder
fso.CreateFolder("hoge")

' FolderExists sample
If fso.FolderExists("hoge") Then
  WScript.Echo "hoge folder exists."
Else
  WScript.Echo "hoge folder not found."
End If

If fso.FolderExists("bar") Then
  WScript.Echo "bar folder exists."
Else
  WScript.Echo "bar folder not found."
End If

' Delete Folder
fso.DeleteFolder("hoge")

Set fso = Nothing

上記のVBScriptサンプルコードは以下のように動作します。

  1. hogeフォルダを作成
  2. FileSystemObjectのFolderExistsメソッドを使いhogeフォルダの存在確認を行う
  3. 同じくFileSystemObjectのFolderExistsメソッドを使い、barフォルダの存在確認を行う
  4. 作成したhogeフォルダを削除する

VBScriptサンプルコード実行結果

C:\wsh>cscript /nologo folderexists.vbs
hoge folder exists.
bar folder not found.


添付ファイル: filefolderexists.vbs 546件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-03-20 (金) 22:50:34