Hello.

I'm having a hard time figuring this out.
I want to open a file, but I don't know the filename. I know the directory the file resides in, and I know the extension ('.lay'), and I know there is only one file with that extension in the directory.

How can I do this and still have portable code?
I was thinking I could get the directory listing and test each file and see if it ends with ".lay".

Any other ideas out there?

Thanks
-V-

Recommended Answers

All 4 Replies

ms-windows call GetFirstFile() and GetNextFile(), or in *nix call opendir() and readdir(). If you used c++ you can use boost library that is portable between these two operating systems (I don't know a thing about MAC).

Damn. I was afraid there wasn't a standard cross-platform way to do this. Oh well, I just have to write a wrapper, then.

Thanks for the fast reply :)

-V-

Yes, wrapper is the way to go then just use precompiler directives to conditionally compile depending on the os.

Member Avatar for iamthwee

I'd go with boost as mentioned before. It will probably be more reliable than writing your own wrapper.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.