C# ファイルの存在チェックを実行する

C#で、File.Existsを使用して、ファイルの存在チェックを実行するサンプルコードを記述してます。
環境
- OS windows10 pro 64bit
- Microsoft Visual Studio Community 2019 Version 16.7.1
File.Exists使い方
File.Existsを使用すると、指定したファイルが存在するか確認することが可能です。
以下は、「chrome.exe」が指定したパスに存在するかを確認するコードとなります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
using System; using System.IO; namespace testapp { class Program { static void Main(string[] args) { string path = @"C:\Program Files\Google\Chrome\Application\chrome.exe"; if (File.Exists(path)) { Console.WriteLine("{0}は存在します", path); // C:\Program Files\Google\Chrome\Application\chrome.exeは存在します } else { Console.WriteLine("{0}は存在しません", path); } } } } |
-
前の記事
Ruby ファイルを1行ずつ読み込む 2021.02.19
-
次の記事
javascript finallyでのreturnは最優先されるので使わない方がいい 2021.02.20
コメントを書く