كيفية معرفة ما إذا كان الملف موجودًا في C# / .NET؟

StackOverflow https://stackoverflow.com/questions/38960

  •  09-06-2019
  •  | 
  •  

سؤال

أرغب في اختبار سلسلة تحتوي على مسار إلى ملف لوجود هذا الملف (شيء مثل ملف -e اختبار في بيرل أو os.path.exists() في بايثون) في C #.

هل كانت مفيدة؟

المحلول

يستخدم:

File.Exists(path)

شبكة MSDN: http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx

يحرر:في System.IO

نصائح أخرى

System.IO.File:

using System.IO;

if (File.Exists(path)) 
{
    Console.WriteLine("file exists");
} 

System.IO.File.Exists(المسار)

msdn

إعطاء المسار الكامل كمدخل.تجنب المسارات النسبية.

 return File.Exists(FinalPath);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top