WSH/ファイルの存在チェックを行う・FileExists
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* ファイルの存在チェックを行う・FileExistsメソッド [#cd8c...
FileSystemObjectのFileExistsメソッドを使用することにより...
以下にFileExistsメソッドを使用したVBScriptサンプルコード...
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* 関連記事 [#j65a8059]
-[[ファイルを行単位で読み込む方法・ReadLineメソッド>WSH/...
-[[ファイルを新規に作成しテキストを書き込むサンプルコード...
-[[既存ファイルをにテキストを追加書き込みするサンプルコー...
-[[ファイルの削除を行う方法・DeleteFile>WSH/ファイルの削...
-[[フォルダの存在チェックを行う・FolderExists>WSH/フォル...
-[[ファイルまたはフォルダーを別の場所にコピーする・Copy>W...
* ファイルの存在チェックを行うVBScriptサンプルコードと実...
以下に、ファイルの存在チェックを行うVBScriptサンプルコー...
** VBScriptサンプルコード [#f056dfa5]
#ref(fileexists.vbs)
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Create Text File
Set tso = fso.OpenTextFile("foo.txt", ForWriting, true)
tso.Close
Set tso = Nothing
If fso.FileExists("foo.txt") Then
WScript.Echo "foo.txt file exists."
Else
WScript.Echo "foo.txt file not found."
End If
If fso.FileExists("bar.txt") Then
WScript.Echo "bar.txt file exists."
Else
WScript.Echo "bar.txt file not found."
End If
Set fso = Nothing
上記のVBScriptサンプルコードは以下のように動作します。~
+foo.txtファイルを作成しクローズ
+FileSystemObjectのFileExistsメソッドを使いfoo.txtのファ...
+同じくFileSystemObjectのFileExistsメソッドを使い、bar.tx...
** VBScriptサンプルコード実行結果 [#q87bdfd7]
C:\wsh>cscript /nologo fileexists.vbs
foo.txt file exists.
bar.txt file not found.
C:\wsh>dir foo.txt
ドライブ C のボリューム ラベルは Windows です
ボリューム シリアル番号は 1234-5678 です
C:\wsh のディレクトリ
2012/07/21 00:53 0 foo.txt
1 個のファイル 0 バイト
0 個のディレクトリ 114,663,075,840 バイ...
C:\wsh>dir bar.txt
ドライブ C のボリューム ラベルは Windows です
ボリューム シリアル番号は 1234-5678 です
C:\wsh のディレクトリ
ファイルが見つかりません
#htmlinsertpcsp(win-btm.html,win-sp.html)
終了行:
#navi(../)
* ファイルの存在チェックを行う・FileExistsメソッド [#cd8c...
FileSystemObjectのFileExistsメソッドを使用することにより...
以下にFileExistsメソッドを使用したVBScriptサンプルコード...
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* 関連記事 [#j65a8059]
-[[ファイルを行単位で読み込む方法・ReadLineメソッド>WSH/...
-[[ファイルを新規に作成しテキストを書き込むサンプルコード...
-[[既存ファイルをにテキストを追加書き込みするサンプルコー...
-[[ファイルの削除を行う方法・DeleteFile>WSH/ファイルの削...
-[[フォルダの存在チェックを行う・FolderExists>WSH/フォル...
-[[ファイルまたはフォルダーを別の場所にコピーする・Copy>W...
* ファイルの存在チェックを行うVBScriptサンプルコードと実...
以下に、ファイルの存在チェックを行うVBScriptサンプルコー...
** VBScriptサンプルコード [#f056dfa5]
#ref(fileexists.vbs)
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Create Text File
Set tso = fso.OpenTextFile("foo.txt", ForWriting, true)
tso.Close
Set tso = Nothing
If fso.FileExists("foo.txt") Then
WScript.Echo "foo.txt file exists."
Else
WScript.Echo "foo.txt file not found."
End If
If fso.FileExists("bar.txt") Then
WScript.Echo "bar.txt file exists."
Else
WScript.Echo "bar.txt file not found."
End If
Set fso = Nothing
上記のVBScriptサンプルコードは以下のように動作します。~
+foo.txtファイルを作成しクローズ
+FileSystemObjectのFileExistsメソッドを使いfoo.txtのファ...
+同じくFileSystemObjectのFileExistsメソッドを使い、bar.tx...
** VBScriptサンプルコード実行結果 [#q87bdfd7]
C:\wsh>cscript /nologo fileexists.vbs
foo.txt file exists.
bar.txt file not found.
C:\wsh>dir foo.txt
ドライブ C のボリューム ラベルは Windows です
ボリューム シリアル番号は 1234-5678 です
C:\wsh のディレクトリ
2012/07/21 00:53 0 foo.txt
1 個のファイル 0 バイト
0 個のディレクトリ 114,663,075,840 バイ...
C:\wsh>dir bar.txt
ドライブ C のボリューム ラベルは Windows です
ボリューム シリアル番号は 1234-5678 です
C:\wsh のディレクトリ
ファイルが見つかりません
#htmlinsertpcsp(win-btm.html,win-sp.html)
ページ名: