You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request]: add "isHiddenFile" property on fs dirent #38809
Is your feature request related to a problem? Please describe.
I found out that using the withFileTypes: true option on fs.readdirSync could return information of whether a file is a directory using the dirent.isDirectory() property, but there's no option to check whether a file is a hidden file. I googled and found out that I can check if a file is hidden in Unix simply by a file name pattern, but, not in windows. As a result, I have to code using c++ and make my own version of fs and call it via child_process, which just makes the program laggy and slower (needs about 100-200ms to load information of a directory whereas fs.readdirSync needs about 10-20ms to read a directory).
Describe the solution you'd like
Fs could provide an isHiddenFile or isHidden or whatever property that just gives information of whether a file/folder is hidden in the system.
Additional Information
For whoever needs a way to filter hidden file, you can do this by using FILE_ATTRIBUTE_HIDDEN of GetFileAttributesA using c++ for the windows, or just by using this /(^|\/)\.[^\/\.]/ regex to implement it for UNIX-like operating system.
Thanks for your comment! I've checked for the package source code and found out this
return basename.charAt(0) === '.'
which is literally just looking if the first character of the basename is a '.' which will of course works fine in Linux. However, hidden files on Windows not presented by the file name, indeed, if you take a look at files on C:\ , there'll be a lot of hidden files with just the proper name, ex: C:\\ProgramData does not start with '.' but still a hidden folder.
My proposal to these hidden items is, to look at the user OS, if it's Windows, we need to call the c++ things, maybe use the libuv (?) as @jasnell mentioned (I'm not familiar with libuv). Otherwise, on UNIX-like Operating Systems just return /(^|\/)\.[^\/\.]/.test(dirent.name)
To get clear, my feature request is the user will be able to get the property of whether a file/folder is hidden from the dirent returned from the {withFileTypes:true} option. The code will be something like this:
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
Activity
bl-ue commentedon May 25, 2021
Hey @kimlimjustin! I'd recommend checking out #38809 — it has several functions relating to hidden file management.
https://www.npmjs.com/package/is-hidden might be of interest, too 🤔
jasnell commentedon May 25, 2021
Ideally, if anything were to be done here, it would be implemented in libuv and surfaced via stat.
kimlimjustin commentedon May 26, 2021
Thanks for your comment! I've checked for the package source code and found out this
which is literally just looking if the first character of the basename is a '.' which will of course works fine in Linux. However, hidden files on Windows not presented by the file name, indeed, if you take a look at files on
C:\, there'll be a lot of hidden files with just the proper name, ex:C:\\ProgramDatadoes not start with '.' but still a hidden folder.My proposal to these hidden items is, to look at the user OS, if it's Windows, we need to call the c++ things, maybe use the libuv (?) as @jasnell mentioned (I'm not familiar with libuv). Otherwise, on UNIX-like Operating Systems just return
/(^|\/)\.[^\/\.]/.test(dirent.name)To get clear, my feature request is the user will be able to get the property of whether a file/folder is hidden from the dirent returned from the
{withFileTypes:true}option. The code will be something like this:Hope my comment is clear enough, best regards,
Justin
bl-ue commentedon Jun 1, 2021
FYI — dirents on macOS and Windows can be hidden with or without a
.at the start of the name.kimlimjustin commentedon Jun 1, 2021
Yeah! That's why package like https://www.npmjs.com/package/is-hidden is useless, thus, I request to add
isHiddenproperty intofs.kimlimjustin commentedon Jun 7, 2021
For those who need this
isHiddenFilefeature, I've created a package to check it, however, I still hope fs could add this feature too!bl-ue commentedon Jun 7, 2021
Cool! Can you link its GitHub repository to the npm package?
kimlimjustin commentedon Jun 7, 2021
I will, thanks!
github-actions commentedon Mar 29, 2022
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
github-actions commentedon Apr 29, 2022
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
For more information on how the project manages feature requests, please consult the feature request management document.