2015-11-26 12:15:02 +00:00
|
|
|
import os
|
2017-05-12 22:47:28 +00:00
|
|
|
import shutil, errno
|
2015-11-26 12:15:02 +00:00
|
|
|
|
2016-02-26 18:50:12 +00:00
|
|
|
|
2015-11-26 12:15:02 +00:00
|
|
|
def get_files_list(path_dir):
|
|
|
|
return os.listdir(path_dir)
|
|
|
|
|
2016-02-26 18:50:12 +00:00
|
|
|
|
2015-11-26 12:15:02 +00:00
|
|
|
def absolute_path_file(path_file):
|
|
|
|
return os.path.abspath(path_file)
|
|
|
|
|
2016-02-26 18:50:12 +00:00
|
|
|
|
2015-11-26 12:15:02 +00:00
|
|
|
def extract_file_from_path_file(path_file):
|
|
|
|
path, file = os.path.split(path_file)
|
|
|
|
return file
|
|
|
|
|
2016-02-26 18:50:12 +00:00
|
|
|
|
2015-11-26 12:15:02 +00:00
|
|
|
def extract_path_from_file(file):
|
|
|
|
path_file = os.path.abspath(os.path.dirname(file))
|
|
|
|
path, file = os.path.split(path_file)
|
|
|
|
return path
|
|
|
|
|
2016-02-26 18:50:12 +00:00
|
|
|
|
2015-11-26 12:15:02 +00:00
|
|
|
def join_paths(path1, path2):
|
|
|
|
return os.path.join(path1, path2)
|
|
|
|
|
2016-02-26 18:50:12 +00:00
|
|
|
|
2015-11-26 12:15:02 +00:00
|
|
|
def file_exists(path_file):
|
2016-02-26 18:50:12 +00:00
|
|
|
return os.path.isfile(path_file)
|
|
|
|
|
2015-12-02 11:16:30 +00:00
|
|
|
|
|
|
|
def dir_exists(dirname):
|
2016-02-26 18:50:12 +00:00
|
|
|
return os.path.isdir(dirname)
|
2017-05-12 22:47:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def copy(src, dst):
|
2018-06-27 18:32:49 +00:00
|
|
|
try:
|
2017-05-12 22:47:28 +00:00
|
|
|
shutil.copytree(src, dst)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno == errno.ENOTDIR:
|
|
|
|
shutil.copy(src, dst)
|
|
|
|
else: raise
|
2018-01-26 19:38:26 +00:00
|
|
|
|
2018-06-27 18:32:49 +00:00
|
|
|
def rename_file(src, dst):
|
|
|
|
try:
|
|
|
|
os.rename(src, dst)
|
2018-06-30 23:36:53 +00:00
|
|
|
return True
|
2018-06-27 18:32:49 +00:00
|
|
|
except OSError as e:
|
2018-06-30 23:36:53 +00:00
|
|
|
if e.errno == errno.ENOENT:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
2018-01-26 19:38:26 +00:00
|
|
|
|
|
|
|
# find a file in the root directory
|
|
|
|
def find(filename, folder):
|
|
|
|
for root, dirs, files in os.walk(folder):
|
|
|
|
return '/'.join((root, filename)) if filename in files else None
|