You might want to use a recursive procedure in conjunction with the os
module. This module has functions for listing directory contents and telling if an item is a directory namely os.listdir
, os.path.isdir
and os.path.isfile
. Using these you should be able to do what you are suggesting relatively easily. I do not know if you wish to preserve the directory structure or not, if not you can simply store the files and discard the directories.
XML, Python - save file structure
-
19-06-2023 - |
Вопрос
I need to scan a large filesystem (1tb) and save this to an XML file. I want this XML file to be structured as described in the code.
Does anybody know how to read a directory and all its subdirectories and files one by one (so they can be added to an XML file) in Python?
<files>
<file id = '1'>
<name>myfile.file</name>
<path>path/to/file/myfile.file</path>
</file>
</files>
Решение
Не связан с StackOverflow