python——(os, shutil)
class Operation_folder():def __init__(self, file_path = ‘‘, folder_path = ‘‘):‘‘‘ @param file_path:the file path ‘‘‘ self.file_path = file_pathself.folder_path = folder_pathdef delete_file(self):‘‘‘ @summary: delete local file ‘‘‘ if os.path.exists(self.file_path): os.remove(self.file_path)def delete_folder(self):‘‘‘ @summary: delete local folder, and its subdirectories ‘‘‘ if os.path.exists(self.folder_path): shutil.rmtree(self.folder_path)def mkdir_dir(self):‘‘‘ @summary:Create a directory and its parent directory ‘‘‘ os.makedirs(self.folder_path)def get_path(self):‘‘‘ @summary: @return: ‘/home/roaddb‘ ‘‘‘ os.path.dirname(‘/home/roaddb/rdb-server-sam.ini‘)def get_file_name(self):‘‘‘ @summary: @return: ‘rdb-server-sam.ini‘ ‘‘‘ os.path.basename(‘/home/roaddb/rdb-server-sam.ini‘)def get_file1_name(self):‘‘‘ @summary: @return: fname: ‘rdb-server-sam‘, ext: .ini ‘‘‘ fname, ext = os.path.splitext(‘rdb-server-sam.ini‘)def get_parent_path(self):‘‘‘ @summary: get the current file dir and the parent dir ‘‘‘ current_path = os.path.abspath(os.path.dirname(__file__)) current_parent_path = os.path.dirname(current_path)return current_path, current_parent_pathif __name__ == "__main__": Of = Operation_folder() Of.get_parent_path()
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16