get file/folder properties in linux

hi, i want to know is file/folder is hidden or not, in linux.

i open folder using opendir function, and traverse using readdir function. For every file/folder i want to print it's properties(isFolder, isHidden, ...). I'm using stat() function to get file/folder properties, but i can't find isHidden flag? Where i must look for this flag?

p.s. sorry for my english;).
There isn't a hidden flag. Are you thinking of MS-DOS (behaviour inherited by Windows)?

http://pubs.opengroup.org/onlinepubs/007908799/xsh/sysstat.h.html
Last edited on
i think i can't explain what i want. i have some c program which prints the contents of some folder. The output format is:

File name:
IsFolder:
IsHidden:

The problem is that i can't find isHidden flag, is directory flag i get from S_ISDIR macros. So i is there some function or macros which gives me this information?

p.s. sorry for my english;).
their name starts with a dot .
However you may want to skip the current ./ and the parent ../ directories.
Last edited on
their name starts with a dot .
However you may want to skip the current ./ and the parent ../ directories.

how it is related to my question? i want to know is there some way to know the hidden attribute of file/folder, this code in windows, i want exactly this but in linux, is it possible?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
WIN32_FIND_DATA data;
HANDLE          handle;

char path[MAX_PATH] = "C:\\Movies\\*";

handle = FindFirstFile(path, &data);

if(INVALID_HANDLE_VALUE != handle)
{
     // I need this code in Linux 
     bool isHidden = data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN;
            
                
}


hope i can explain what i want)

check the name, if it starts with a dot, then it is hidden.
Also often files ending with a tilde '~'.
There is no hidden flag in *nix AFAIK. They simply adopted the conventions listed above (./~ etc) to denote hidden files.
thanks everybody for help)!

i have one more question, it is about readdir function, i create little program, which prints the number of children(folders/files) of the folder. But when i run program and compare results with results of explorer properties, they are different. I guess explorer doesn't count system files, but my program does. So my question, what i must do to get the same results as linux explorer?

here is some of my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
char path[PATH_MAX] = "/home/akmal/Desktop/Work Documents";
struct DIR * dr = opendir(path);
struct dirent * drnt;

while( (drnt = readdir(dr) ) != NULL )
{
     struct stat statBuf;
     int isFolder;
     char fullPath[PATH_MAX];

     strcpy(fullPath, path);
     strcat(fullPath, "/");
     strcat(fullPath, drnt->d_name);

      if( stat(fullPath, &statBuf) < 0 )
           return false;

      isFolder = S_ISDIR(statBuf.st_mode);

      printf("name = %s\n", drnt->d_name);
      printf("isfolder = %d", isFolder);
    
}


Topic archived. No new replies allowed.