Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个属性,它保存 filenameOnly 没有扩展名。
string fileNameOnly = "myFileName";
现在我想对选定位置执行多项检查,例如c:\现有文件名+文件扩展名(.jpg, .png, .gif, .bmp)
c:\
(.jpg, .png, .gif, .bmp)
因此,如果c:\myFileName.jpg存在,则将该值分配给string filename="myFileName.jpg"变量。
c:\myFileName.jpg
string filename="myFileName.jpg"
最好和最快的方法是什么?
尝试这样的事情来获取适合您模式的文件数组:
string[] files = Directory.GetFiles( DirectoryPath, String.Format("{0}.*", fileNameOnly));