zoukankan      html  css  js  c++  java
  • python——(os, shutil)

    class Operation_folder():
    def __init__(self, file_path = '', folder_path = ''):
    '''
    @param file_path:the file path
    '''
    self.file_path = file_path
    self.folder_path = folder_path

    def 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_path


    if __name__ == "__main__":

    Of = Operation_folder()
    Of.get_parent_path()
  • 相关阅读:
    15 鼠标事件
    09 属性操作
    06 DOM操作之插入节点
    03 如何处理多个库$冲突的问题
    01 jquery引入
    08 千千音乐盒实现全选和反选
    03 衣服相册切换效果
    02 显示和隐藏图片
    01 图片切换
    派生
  • 原文地址:https://www.cnblogs.com/ting152/p/12580526.html
Copyright © 2011-2022 走看看