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. How to Detect Invalid Filenames

How to Detect Invalid Filenames

Scheduled Pinned Locked Moved C / C++ / MFC
businessjsonhelptutorialquestion
3 Posts 3 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.
  • S Offline
    S Offline
    Steve Thresher
    wrote on last edited by
    #1

    Is there an API available to check if a filename is valid. At the moment the only information I can find is in the help for CreateFile() where it gives a list of invalid characters and filenames such as ./?\* or com1,con,lpt. Systems AXIS Ltd - Software for Business ...

    V P 2 Replies Last reply
    0
    • S Steve Thresher

      Is there an API available to check if a filename is valid. At the moment the only information I can find is in the help for CreateFile() where it gives a list of invalid characters and filenames such as ./?\* or com1,con,lpt. Systems AXIS Ltd - Software for Business ...

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      try/catch opening the file with specified filename? "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

      1 Reply Last reply
      0
      • S Steve Thresher

        Is there an API available to check if a filename is valid. At the moment the only information I can find is in the help for CreateFile() where it gives a list of invalid characters and filenames such as ./?\* or com1,con,lpt. Systems AXIS Ltd - Software for Business ...

        P Offline
        P Offline
        PengFeidu
        wrote on last edited by
        #3

        Hello! if you only check the string of the filename,you can check if the string have the list of "./?;'". if you check whether the file is existent, you can use code as follow in VC6.0 : BOOL CheckIfFileExists (LPCTSTR szFileName) { ASSERT( szFileName != NULL ); if( _tcslen(szFileName) == 0 ) return FALSE; DWORD dwAttr = GetFileAttributes(szFileName); if( dwAttr == 0xFFFFFFFF ) return FALSE; return (dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0; } dupengfei

        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