Skip to content

Create a Function to List Hidden Files in a Directory #75

@hbisneto

Description

@hbisneto

Description:

Develop a Python function that lists all hidden files in a specified directory. The function should be compatible with Windows, Linux, and macOS operating systems.

Requirements:

  1. Function Name: get_hidden_files
  2. Parameters:
    • directory (str): The path to the directory where hidden files need to be listed.
  3. Returns:
    • A list of hidden files in the specified directory.

Specifications:

  • The function should use the os module to interact with the file system.
  • For Windows, hidden files are identified by the FILE_ATTRIBUTE_HIDDEN attribute.
  • For Linux and macOS, hidden files are identified by a leading dot (.) in the filename.
  • The function should handle exceptions gracefully, such as invalid directory paths or permission errors.

Example Usage:

from filesystem import file as fsfile
hidden_files = fsfile.get_hidden_files('/path/to/directory')
print(hidden_files)

Implementation Hints:

  • Use file.get_files() to list all files in the directory.
  • For Windows, consider using the ctypes library to check file attributes.

Additional Notes:

  • Ensure the function is well-documented with comments explaining each step.
  • Write unit tests to verify the function works correctly on all three operating systems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions