hi , every one
can i get file type using C >>>?
if the is passable please tell me about the way to get it ...?
with my respect
hi , every one
can i get file type using C >>>?
if the is passable please tell me about the way to get it ...?
with my respect
There are two common understandings of file type:
1) distinguishing regular files (text, binary data, images, executables, etc) from directories, links, and other special files (such as fifos). This is mostly a *nix thing I think, where you also have files that are sockets, files that are device interfaces, etc. The file system maintains an attribute indicating whether a file is a reg file, a directory, a link, etc.
2) file type based on extension, eg, .txt, .exe, .jpeg, etc.
You can do both; the first one is OS specific, the second one just requires parsing the filename.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
And file types can be obfuscated somewhat, calling a .zip file .txt might make it look to the casual observer as a text file but it really isn't. Do you mean to truly distinguish such things? If so, the level of complexity just went up quite a bit (an understatement perhaps).
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Thanks "MK27"
for UR qukly answer
yes i mean how to get type file (regular files (text, binary data, images, executables, etc))
by using turbo c ....?
Using stat function we can get the file type. As well as in unix we can use the stat command also.But stat command lot of situations give regular file as the type. Better we can use stat function.
The field st_mode used to check the file type in stat function.
The structure fill up with an attributes of the given file. For more details read "man 2 stat".Code:syntax: int stat(const char *path, struct stat *buf);
Using file command also we can get the file type.
Example
Output of the above program is,Code:#include<stdio.h> int main(int argc,char *argv[]) { system("file filetype.c"); system("file ."); //'.' (dot) represents current directory. }
filetype.c: ASCII C program text
.: directory
If you want to know any useful file type info such as whether it's an AVI, MPEG, MP3... you'll need to know the file format of all those types and read the file to see if it matches the pattern. It gets pretty hard since there are so many file types (and things like AVI have many different formats) that you'd have to look around forever searching for info about file types. One of my previous companies tried to do that, and it wasn't easy.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010