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
Printable View
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.
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).
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.