Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Valid File Name

Valid File Name

Scheduled Pinned Locked Moved C / C++ / MFC
c++combusinessquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jack Puppy
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • J Jack Puppy

      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

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      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 or CoInitializeEx somewhere in your process. Steve

      J 1 Reply Last reply
      0
      • S Stephen Hewitt

        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 or CoInitializeEx somewhere in your process. Steve

        J Offline
        J Offline
        Jack Puppy
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • J Jack Puppy

          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

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups