#!/usr/bin/python

import os
import sys
files_list = []
def print_files(path):
    lsdir = os.listdir(path)
    dirs = [i for i in lsdir if os.path.isdir(os.path.join(path, i))]
    if dirs:
        for i in dirs:
            print_files(os.path.join(path, i))
    files = [i for i in lsdir if os.path.isfile(os.path.join(path,i))]
    for f in files:
        files_list.append(os.path.join(path, f))
        #print(os.path.join(path, f))
    return files_list

def file_extension(path):
    return os.path.splitext(path)[1]

def clear_log(file):
    file_ext = file_extension(file)
    #print(file_ext)
    if '.log' in file_ext:
        modify_text(file)
    return

def modify_text(log_file):
    os.remove(log_file)
    #with open(log_file, 'w'):
        #pass

files = print_files('/apps/')
for file in files:
    if os.path.isfile(file):
        clear_log(file)

python paramiko(SFTP) 相关文档

python paramiko SFTP文档地址: http://docs.paramiko.org/en/2.4/api/sftp.html import paramiko host = "THEHOST.com" #...

阅读全文

python 执行cmd命令并获取pid

process = subprocess.Popen('cmd命令') pid = process.pid print(pid)

阅读全文

适用于python 3+ pymsql 扩展类

适用于python 3+ pymsql 扩展类,包含增删改查 首先要安装pymsql , pip install pymysql document : https://pypi.org/project/PyMySQL/ github :https:/...

阅读全文

欢迎留言