Gary Willoughby
Gary Willoughby

Reputation: 52508

Using D on Linux how do i determine if a file is hidden?

I'm creating a simple file walker to list some files and need to omit hidden files from the results. I'm currently doing something like this:

private void Walk()
{
    this.Files          = [];
    this.Directories    = [];
    DirIterator Entries = dirEntries(this.Directory, SpanMode.depth, this.FollowSymLinks);

    foreach (DirEntry Entry; Entries)
    {
        version(Windows)
        {
            uint Attributes = Entry.attributes();
            if (Attributes & FILE_ATTRIBUTE_HIDDEN)
            {
                continue;
            }
        }

        version(linux)
        {
            // ?????
        }

        if (Entry.isFile())
        {
            this.Files ~= Entry.name;
            this.NumberOfFiles++;
        }

        if (Entry.isDir())
        {
            this.Directories ~= Entry.name;
            this.NumberOfDirectories++;
        }
    }

    this.Walked = true;
}

The windows section seems to work fine but what do i need to do for the Linux section to determine if a file is hidden?

Upvotes: 2

Views: 231

Answers (1)

Mike McMahon
Mike McMahon

Reputation: 8614

In linux files/directories are hidden if they are prefaced with a . so check to see if the file/directory name starts with a .

for example

.m2/ and .somefile.txt would be hidden on linux where as m2/ and somefile.txt would not.

Upvotes: 5

Related Questions