

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Calculator App
incomplete
2: Validate Paths
incomplete
3: List Files
incomplete
4: Get File Content
incomplete
5: Write Files
incomplete
6: Run Python
incomplete
This lesson's interactive features are locked, please to keep using them
We've set up get_files_info to safely validate the requested directory; now let's make it actually list files.
- 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.
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
Result for 'pkg' directory:
- calculator.py: file_size=1721 bytes, is_dir=False
- render.py: file_size=376 bytes, is_dir=False
Result for '/bin' directory:
Error: Cannot list "/bin" as it is outside the permitted working directory
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.
Here are some standard library functions you'll find helpful:
os.listdir(): List the contents of a directoryos.path.isdir(): Check if a path points to an existing directoryos.path.getsize(): Get the size of a file (in bytes).join(): Join a list of strings together with a given separator