Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
saephoed 11-Jan-14 6:57am    
Which OS (es) are you targeting?

1 solution

See here: Directory.GetFiles[^]
A modified version of the example it gives:
C++
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.
 
Share this answer
 
Comments
[no name] 11-Jan-14 4:52am    
Canonical.
Philippe Mori 13-Jan-14 18:08pm    
This is a good solution if the user write C++/CLI code which is different from standard C++. Otherwise, I think the soilution would dépends on the platform...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900