首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Python 基于Python实现的ssh兼sftp客户端(下)

#!/usr/bin/env/ python # -*- coding:utf-8 -*- __author__ = 'laifuyu' import os import subprocess class OtherTools: def __init__(self): self.filepath_list = [] # 批量创建目录 def mkdirs_once_many(self, path): path = os.path.normpath(path) # 去掉路径最右侧的 \\ 、/ path = path.replace('\\', '/') # 将所有的\\转为/,避免出现转义字符串 head, tail = os.path.split(path) new_dir_path = '' # 反转后的目录路径 root = '' #根目录 if not os.path.isdir(path) and os.path.isfile(path): # 如果path指向的是文件,则继续分解文件所在目录 head, tail = os.path.split(head) if tail == '': return while tail: new_dir_path = new_dir_path + tail + '/' head, tail = os.path.split(head) root = head else: new_dir_path = root + new_dir_path # 批量创建目录 new_dir_path = os.path.normpath(new_dir_path) head, tail = os.path.split(new_dir_path) temp = '' while tail: temp = temp + '/' + tail dir_path = root + temp if not os.path.isdir(dir_path): os.mkdir(dir_path) head, tail = os.path.split(head)

02
领券