Skip to content

[Feature Request]: add "isHiddenFile" property on fs dirent #38809

Closed

Description

@kimlimjustin

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.

Activity

  1. added
    feature requestIssues requesting new Node.js features.
    fsIssues and PRs related to file-system APIs and the fs module.
    on May 25, 2021
  2. bl-ue commented on May 25, 2021

    @bl-ue
    Contributor

    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 🤔

  3. jasnell commented on May 25, 2021

    @jasnell
    Member

    Ideally, if anything were to be done here, it would be implemented in libuv and surfaced via stat.

  4. kimlimjustin commented on May 26, 2021

    @kimlimjustin
    Author

    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 🤔

    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:

    const files = fs.readdirSync(FilePath, { withFileTypes: true }).map(dirent => { return { "filename": dirent.name, "isDir": dirent.isDirectory(), "isHidden": dirent.isHidden() } })
    

    Hope my comment is clear enough, best regards,
    Justin

  5. bl-ue commented on Jun 1, 2021

    @bl-ue
    Contributor

    FYI — dirents on macOS and Windows can be hidden with or without a . at the start of the name.

  6. kimlimjustin commented on Jun 1, 2021

    @kimlimjustin
    Author

    FYI — dirents on macOS and Windows can be hidden with or without a . at the start of the name.

    Yeah! That's why package like https://www.npmjs.com/package/is-hidden is useless, thus, I request to add isHidden property into fs.

  7. kimlimjustin commented on Jun 7, 2021

    @kimlimjustin
    Author

    For those who need this isHiddenFile feature, I've created a package to check it, however, I still hope fs could add this feature too!

  8. bl-ue commented on Jun 7, 2021

    @bl-ue
    Contributor

    Cool! Can you link its GitHub repository to the npm package?

  9. kimlimjustin commented on Jun 7, 2021

    @kimlimjustin
    Author

    Cool! Can you link its GitHub repository to the npm package?

    I will, thanks!

  10. github-actions commented on Mar 29, 2022

    @github-actions
    Contributor

    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.

  11. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Mar 29, 2022
  12. moved this to Pending Triage in Node.js feature requestson Mar 29, 2022
  13. moved this from Pending Triage to Stale in Node.js feature requestson Mar 29, 2022
  14. github-actions commented on Apr 29, 2022

    @github-actions
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.fsIssues and PRs related to file-system APIs and the fs module.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions