get_file_list

swpy.lib.utilities.get_file_list(path, recursive=False)

Bring the files in path to the list. Generally, only files in depth 1 from path are fetched. If recursive is True, all files in subdirectories are included in the list. The files imported into the list contain extension and directory structure information. If it fails to get the file list, it returns None. If path is file, only that file is imported into the list. Since it was created based on os.scandir function, the hidden file is also included in the list. If you do not have permission to execute os.stat function, you can return None even if the actual path exists.

Parameters
  • path (str, optional) – Path to get file list.

  • recursive (bool) –

    Whether to include all files in subdirectories. Default is False.

    (True: Included / False: Not included)

Returns

list – File name list / None (Success / Fail)

Examples

>>> get_file_list("dir1/", False)
["file1.txt", "file2.txt"]
>>> get_file_list("dir1/", True)
[“file1.txt”, “file2.txt”, “dir2/fileA.txt”, “dir2/dir3/file_a.txt”]
>>> get_file_list("dir1/file1.txt", False)
[“file1.txt”]