To get the type of file we can execute the command
system("file --mime-type -b filename");
The output displays in to terminal.But could not store the file type using the command
char file_type[40] = system("file --mime-type -b filename");
So how to store file type as a string using system(file) function.
See the man page of system
: It does not return the output of the command executed (but an errorcode or the return value of the command).
What you want is popen
. It return a FILE*
which you can use to read the output of the command (see popen
man page for details).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With