We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

List Files

We've set up get_files_info to safely validate the requested directory; now let's make it actually list files.

Assignment

  1. - README.md: file_size=1032 bytes, is_dir=False
    - src: file_size=128 bytes, is_dir=True
    - package.json: file_size=1234 bytes, is_dir=False
    

    I've listed some useful standard library functions in the Tips section below.

    The exact file sizes and even the order of files may vary depending on your operating system and file system. Your output doesn't need to match the example byte-for-byte, just the overall format.

    1. Result for current directory:
        - main.py: file_size=719 bytes, is_dir=False
        - tests.py: file_size=1331 bytes, is_dir=False
        - pkg: file_size=44 bytes, is_dir=True
      
    2. Result for 'pkg' directory:
        - calculator.py: file_size=1721 bytes, is_dir=False
        - render.py: file_size=376 bytes, is_dir=False
      
    3. Result for '/bin' directory:
          Error: Cannot list "/bin" as it is outside the permitted working directory
      
    4. Result for '../' directory:
          Error: Cannot list "../" as it is outside the permitted working directory
      

    To import from a subdirectory, use this syntax: from DIRNAME.FILENAME import FUNCTION_NAME

    Where DIRNAME is the name of the subdirectory, FILENAME is the name of the file without the .py extension, and FUNCTION_NAME is the name of the function you want to import.

Run and submit the CLI tests.

Tips

Here are some standard library functions you'll find helpful: