I would like to test a string containing a path to a file for existence of that file (something like the -e
test in Perl or the os.path.exists()
in Python) in C#.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use:
File.Exists(path)
MSDN: http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
Edit: In System.IO
回答2:
System.IO.File:
using System.IO;
if (File.Exists(path))
{
Console.WriteLine("file exists");
}
回答3:
System.IO.File.Exists(path)
msdn
回答4:
Give full path as input. Avoid relative paths.
return File.Exists(FinalPath);