r"""Return a file list in a folder by given a path and regular expression. Parameters ---------- path : str or None A folder path, if `None`, use the current directory. regx : str The regx of file name. printable : boolean Whether to print the files infom
(path=None, regx='\.jpg', printable=True, keep_prefix=False)
| 2323 | |
| 2324 | |
| 2325 | def load_file_list(path=None, regx='\.jpg', printable=True, keep_prefix=False): |
| 2326 | r"""Return a file list in a folder by given a path and regular expression. |
| 2327 | |
| 2328 | Parameters |
| 2329 | ---------- |
| 2330 | path : str or None |
| 2331 | A folder path, if `None`, use the current directory. |
| 2332 | regx : str |
| 2333 | The regx of file name. |
| 2334 | printable : boolean |
| 2335 | Whether to print the files infomation. |
| 2336 | keep_prefix : boolean |
| 2337 | Whether to keep path in the file name. |
| 2338 | |
| 2339 | Examples |
| 2340 | ---------- |
| 2341 | >>> file_list = tl.files.load_file_list(path=None, regx='w1pre_[0-9]+\.(npz)') |
| 2342 | |
| 2343 | """ |
| 2344 | if path is None: |
| 2345 | path = os.getcwd() |
| 2346 | file_list = os.listdir(path) |
| 2347 | return_list = [] |
| 2348 | for _, f in enumerate(file_list): |
| 2349 | if re.search(regx, f): |
| 2350 | return_list.append(f) |
| 2351 | # return_list.sort() |
| 2352 | if keep_prefix: |
| 2353 | for i, f in enumerate(return_list): |
| 2354 | return_list[i] = os.path.join(path, f) |
| 2355 | |
| 2356 | if printable: |
| 2357 | logging.info('Match file list = %s' % return_list) |
| 2358 | logging.info('Number of files = %d' % len(return_list)) |
| 2359 | return return_list |
| 2360 | |
| 2361 | |
| 2362 | def load_folder_list(path=""): |
no outgoing calls
no test coverage detected
searching dependent graphs…