5,337
edits
(→Usage) |
|||
Line 76: | Line 76: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Filesystem | ===Filesystem=== | ||
====Paths==== | |||
Use <code>os.path</code> | |||
<syntaxhighlight lang="python"> | |||
import os.path as path | |||
my_file = path.join("folder_1", "my_great_dataset.tar.gz") | |||
# "folder_1\\my_great_dataset.tar.gz" | |||
# Get the filename with extension | |||
filename = path.basename(my_file) | |||
# "my_great_dataset.tar.gz" | |||
# Get the filename without extension | |||
filename_no_ext = path.splitext(filename)[0] | |||
# Note that splitext returns ("my_great_dataset.tar", ".gz") | |||
</syntaxhighlight> | |||
====List all files in a folder==== | ====List all files in a folder==== | ||
[https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory Reference] | [https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory Reference] |