how to get file name and its type using metadata in linux using c code example
Example 1: find the size of file in linux
ls -l filename #Displays Size of the specified file
ls -l * #Displays Size of All the files in the current directory
ls -al * #Displays Size of All the files including hidden files in the current directory
ls -al dir/ #Displays Size of All the files including hidden files in the 'dir' directory
Example 2: how to check the size of a file in linux c
If you have the file stream (FILE * f):
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
Or,
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
fd = fileno(f);
struct stat buf;
fstat(fd, &buf);
int size = buf.st_size;
Or, use stat, if you know the filename:
#include <sys/stat.h>
struct stat st;
stat(filename, &st);
size = st.st_size;
Example 3: create a file in the directory of the exe and write to it c#
string GuarnteedWritePath = System.Environment.
GetFolderPath(
Environment.SpecialFolder.CommonApplicationData
);
string FilePath = Path.Combine(GuarnteedWritePath, "LogFile.txt");