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. Determine text file or Binary file

Determine text file or Binary file

Scheduled Pinned Locked Moved C / C++ / MFC
jsonquestion
4 Posts 4 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.
  • M Offline
    M Offline
    mjvalan
    wrote on last edited by
    #1

    I want to determine, a file is text file or binary file(file name dosen't have file extension).Is there any API in Windows SDK? Thanks MJVALAN

    B D D 3 Replies Last reply
    0
    • M mjvalan

      I want to determine, a file is text file or binary file(file name dosen't have file extension).Is there any API in Windows SDK? Thanks MJVALAN

      B Offline
      B Offline
      basementman
      wrote on last edited by
      #2

      You can open the file, read the contents, and examine the bytes to determine if the file contains any binary data. You can see if the characters are in the normal text range, as well as checking for CR/LF characters.  onwards and upwards...

      1 Reply Last reply
      0
      • M mjvalan

        I want to determine, a file is text file or binary file(file name dosen't have file extension).Is there any API in Windows SDK? Thanks MJVALAN

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        A file is only "text" or "binary" in the context of the application that created it. Historically speaking, if the file contained non-printable characters, it was considered binary. Otherwise, it was considered text. What exactly is it that you are trying to do?


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        1 Reply Last reply
        0
        • M mjvalan

          I want to determine, a file is text file or binary file(file name dosen't have file extension).Is there any API in Windows SDK? Thanks MJVALAN

          D Offline
          D Offline
          digwizfox
          wrote on last edited by
          #4

          I don't think so. This wouldn't make any sense to me. After all, a binary file appears as garbage in a text editor because the bytes will not map to ascii to form any kind of intelligible sentence in any language. The text editor doesn't care if the file you tell it to open is binary or not. It will just read the file and try to map the bytes into ascii and display whatever random characters the data happens to map to. If there were an automatic function for doing this, the people that wrote notepad and wordpad probably would have popped up an warning message reading, "warning, processing binary file"; or something like that. All files are binary files, in my mind. It just so happens that a text file is a special kind of binary file where each byte maps to an appropriate ascii symbol to form intelligible letters/numbers/symbols. Even the carriage returns and line feeds are simply bytes of data that map to the appropriate ascii symbol. I think writing an algorithm to guess if something is good enough to be a text file would be awfully difficult if not impossible. You'd have to read each byte in and make a lot of assumptions about the data.

          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