Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add omit_hidden option to readdir ? #38841

Open
CameronBieganek opened this issue Dec 11, 2020 · 9 comments
Open

Add omit_hidden option to readdir ? #38841

CameronBieganek opened this issue Dec 11, 2020 · 9 comments

Comments

@CameronBieganek
Copy link
Contributor

I couldn't find an issue for this. I was expecting there to be an optional keyword argument for readdir to omit hidden files and directories. Currently I'm doing this

function non_hidden_files(dir; kwargs...)
    files = readdir(dir; kwargs...)
    filter(!startswith(".")  basename, files)
end

which works for hidden files but not for hidden directories. It seems like it would be handy to have an omit_hidden or similar option for readdir.

I encountered this because of the pesky .DS_Store files on MacOS. 😂

@StefanKarpinski
Copy link
Member

Define hidden file...

@CameronBieganek
Copy link
Contributor Author

True, I have no idea how hidden files work on Windows. I'm not a Windows user...

@StefanKarpinski
Copy link
Member

StefanKarpinski commented Dec 12, 2020

Well, define hidden on macOS then... There's at least two or three notions of this on macOS.

@stevengj
Copy link
Member

stevengj commented Dec 18, 2020

One could define "hidden" as "does not appear in default directory listings in the standard file-picker interface for that OS", I suppose.

On Windows, one could use GetFileAttributesW and check whether the file has FILE_ATTRIBUTE_HIDDEN, I think.

Presumably one could implement something to check for hidden files on MacOS as well.

How useful would a filesystem-specific ishidden function be?

@StefanKarpinski
Copy link
Member

I think that would be the first step. It could just check for leading dot in the name for Linux; for macOS it would check that plus the three other kinds of hiddenness; for Windows the GetFileAttributesW thing. There are some additional considerations: is a path hidden if some prefix of it is hidden? Or only if the last component is hidden?

@fonsp
Copy link
Member

fonsp commented Feb 23, 2022

This would be great for UI applications written in Julia :)

It looks like Python 3.5 started including the output of GetFileAttributesW in the output of stat: https://docs.python.org/3/library/stat.html#stat.FILE_ATTRIBUTE_HIDDEN This might be nice to add to Julia's stat?

(I also found that Python and NodeJS do not have "hidden file" in their stdlib, perhaps because it is not as well-defined outside of windows)

@jakewilliami
Copy link

Thanks for raising this issue @CameronBieganek . I agree that this functionality would be useful, although it needn't necessarily be in Base. As such, I've begun work on a library (HiddenFiles.jl) to hide away all of the nastiness/nuance of hidden files on different systems. It's very much a work in progress, but it's getting there. Still need to register the package, but will do that after I make proper tests/CI/documentation, and finish implementing a solution for BSD.

@StefanKarpinski, you mentioned there are three things to check after checking for a leading . when it comes to macOS, however, I've only found one other criteria (UF_HIDDEN). Do you have any resources on the others? Perhaps @stevengj is more familiar with macOS hidden files?

Also, is there a consensus on your earlier question?:

is a path hidden if some prefix of it is hidden? Or only if the last component is hidden?

@stevengj
Copy link
Member

See this link for macOS hidden files.

@jakewilliami
Copy link

Thanks @stevengj, I saw that link from your previous comment, however it felt very high-level. If that's the best that there is then I can probably work from that, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants