generated from pavel.muhortov/template-bash
add Do.file_search()
This commit is contained in:
parent
8d44f2a4f3
commit
2079c7f951
|
@ -12,7 +12,7 @@ from argparse import ArgumentParser
|
|||
from datetime import datetime
|
||||
from ftplib import FTP
|
||||
from multiprocessing import Process, Queue
|
||||
from os import path, sep, makedirs, remove, replace, environ
|
||||
from os import environ, makedirs, path, remove, replace, sep, walk
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
from sys import platform
|
||||
from time import sleep
|
||||
|
@ -2346,6 +2346,30 @@ class Do():
|
|||
}
|
||||
return date
|
||||
|
||||
@staticmethod
|
||||
# pylint: disable=W0612
|
||||
def file_search(root_path: str, search_name: (str, type(None)) = None) -> list:
|
||||
"""Search files.
|
||||
|
||||
Args:
|
||||
root_path (str): where to search.
|
||||
search_name (str, type, optional): full or partial filename for the filter.
|
||||
Defaults to None.
|
||||
|
||||
Returns:
|
||||
list: list of found files.
|
||||
"""
|
||||
found_list = []
|
||||
if Do.args_valid(locals(), Do.file_search.__annotations__):
|
||||
for root, dirs, files in walk(root_path, topdown=False):
|
||||
for file in files:
|
||||
if search_name:
|
||||
if search_name in file:
|
||||
found_list.append(path.join(path.realpath(root), file))
|
||||
else:
|
||||
found_list.append(path.join(path.realpath(root), file))
|
||||
return found_list
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
time_start = datetime.now()
|
||||
|
|
Loading…
Reference in New Issue
Block a user