Valid File Name
-
Is there a function in Win32/MFC that will determine if a file name is valid? I'm looking for something that tests for the conditions mentioned in this article under the Naming Conventions heading. "My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
-
Is there a function in Win32/MFC that will determine if a file name is valid? I'm looking for something that tests for the conditions mentioned in this article under the Naming Conventions heading. "My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
There are probably lots of ways, but try this:
IMoniker* pMonk; HRESULT hr = CreateFileMoniker(OLESTR("C:\\auxa.txt"), &pMonk); if ( SUCCEEDED(hr) ) { // Valid! pMonk->Release(); }
Be sure you've called
OleInitialize
,CoInitialize
orCoInitializeEx
somewhere in your process. Steve -
There are probably lots of ways, but try this:
IMoniker* pMonk; HRESULT hr = CreateFileMoniker(OLESTR("C:\\auxa.txt"), &pMonk); if ( SUCCEEDED(hr) ) { // Valid! pMonk->Release(); }
Be sure you've called
OleInitialize
,CoInitialize
orCoInitializeEx
somewhere in your process. SteveDoesn't work. (they're all valid) I went through a slew of file based functions, including things like GetShortFileName, hoping for a failure if the name was invalid, none worked. I guess I'll just use a regular expression. "My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
-
Doesn't work. (they're all valid) I went through a slew of file based functions, including things like GetShortFileName, hoping for a failure if the name was invalid, none worked. I guess I'll just use a regular expression. "My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
I used the following code: -------------------------- void IsValid(LPCOLESTR pFileName) { IMoniker* pMonk; HRESULT hr = CreateFileMoniker(pFileName, &pMonk); if ( SUCCEEDED(hr) ) { pMonk->Release(); wcout << L"'" << pFileName << L"' is valid.\n"; return; } wcout << L"'" << pFileName << L"' is NOT valid.\n"; } int main(int argc, char* argv[]) { OleInitialize(NULL); IsValid(OLESTR("auxa.txt")); IsValid(OLESTR("aux.txt")); IsValid(OLESTR("aux .txt")); IsValid(OLESTR("C:\\ filename.txt")); IsValid(OLESTR("C:\\auxa.txt")); IsValid(OLESTR("C:\\aux.txt")); IsValid(OLESTR("C:\\aux .txt")); OleUninitialize(); return 0; } And got this in output: ----------------------- 'auxa.txt' is valid. 'aux.txt' is valid. 'aux .txt' is valid. 'C:\filename.txt ' is valid. 'C:\auxa.txt' is valid. 'C:\aux.txt' is NOT valid. 'C:\aux .txt' is NOT valid. Seems to work only for fully qualifed paths. Seems to fail the trailing space rule in any case. Steve