开发者

How do I find if the file MyFile.03 is in the folder MyTmpFolder?

H开发者_如何学Cow do I find if the file MyFile.03 is in the folder MyTmpFolder using C# and Winforms?


Use

System.IO.File.Exists("MyTempFolder\\MyFile.02");


System.IO.File [] files=Directory.GetFiles(dirpath);

foreach(File f1 in files) { if(f1.SubString(0,f1.lastIndexOF('.'))=="MyFile.02") { File myFile=f1; } }


The System.IO namespace contains members to help us work with input and output operations (a category which file operations fall under), so using the Path class we can manipulate file and folder paths and using the File class we can operate on files - this ought to do the trick for you:

using System.IO;

var exists = File.Exists(Path.Combine(MyTmpFolder, MyDesiredFile));


bool doesExist = File.Exists("MyTmpFolder\\MyFile.02");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜