Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
963 B
2
Indexable
import shutil
import os
import datetime
import re

cwd = os.getcwd()

# create temp folder
os.mkdir('temp')

# create string for temp
temp = os.path.join(cwd, 'temp')

# get list of folders
dir = os.listdir()

# regex for "20230423T173218"
regex = re.compile(r'\d{8}T\d{6}')

# filter dir with regex
filtered = list(filter(regex.search, dir))

for session in filtered:
    for d in os.walk(session):
        for f in d[-1]:
            if "GitHub Copilot.log" in f:
                print(f)
                src_dir = os.path.join(d[0], f)
                ctime = os.path.getctime(src_dir)
                ctime = datetime.datetime.fromtimestamp(ctime).strftime('%Y%m%dT%H%M%S')
                dst_dir = os.path.join(temp, f"{ctime}.log")
                shutil.copy(src_dir, dst_dir)


# time now
now = datetime.datetime.now().strftime('%Y%m%dT%H%M%S')

# zip temp folder
shutil.make_archive(f"logs_{now}", 'zip', temp)

# delete temp folder
shutil.rmtree(temp)