Find the answer to your Linux question:
Results 1 to 3 of 3
I'm making a program and I need to know what if a file is a wav without using it's extension (as it can be random in my instance). In the ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    1

    C :: Detecting file type

    I'm making a program and I need to know what if a file is a wav without using it's extension (as it can be random in my instance). In the file's properties, it says something like Mime: wav/audio. I want to get that info for my program. Any clues on where to start?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    These things are usually determined by something called the magic number: a unique identifier in the first few bytes of the file. You can check the file man page for some info on how it identifies files. Maybe play around with it and see how you can use it.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    you could use "od" to look for the magic number:
    take several .wav files 1.wav, 2.wav, 3.wav say:

    od 1.wav
    od 2.wav
    od.3.wav

    see whether the first few bytes have a magic number;
    if so, then in your program, after you open the file,
    you can look for the magic number.
    the sun is new every day (heraclitus)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...