如何在不指定文件扩展名的情况下检查文件是否存在
问题描述:
大家好,
我想知道如何在没有扩展名的情况下检查文件是否存在然后获得扩展名?
例如假设文件名为 myfile和扩展名可能是.jpg .png或.gif,但我不知道哪个。
任何帮助都将不胜感激。
谢谢,
Devadutta。
Hi All,
I wanted to know how I could check if a file exists without the extension and then get the extension?
For example suppose the filename is "myfile" and the extension could be .jpg .png or .gif but I wont know which.
Any help would be appreciated.
Thanks,
Devadutta.
答
请参阅: Directory.GetFiles [ ^ ]
它给出的示例的修改版本:
See here: Directory.GetFiles[^]
A modified version of the example it gives:
array<String^>^dirs = Directory::GetFiles( "D:\\Temp\\", "myfile.*" );
Console::WriteLine( "Found: {0}", dirs->Length );
数组将包含每个文件的完整路径,包括扩展名。
The array will contain the full path to each file, including the extension.