Skip to content

Instantly share code, notes, and snippets.

@diogotito
Last active June 22, 2022 23:40
Show Gist options
  • Save diogotito/fec19c3c8c33aaa9507c8cb566ee557a to your computer and use it in GitHub Desktop.
Save diogotito/fec19c3c8c33aaa9507c8cb566ee557a to your computer and use it in GitHub Desktop.
Make an Everything File List from 7z output
from collections import namedtuple
from csv import DictWriter
from datetime import datetime
SEVENZ_OUTPUT = "7z_output.txt" # Name of file with `7z l <FILE> -slt` output
EFU_FILENAME = "7z_filelist.efu" # Name of Everything File List to write
conv = namedtuple("conversion", ("efu_column", "fn"))
pass_fn = lambda x: x
date_fn = lambda dt: datetime.strptime(dt, "%Y-%m-%d %H:%M:%S").isoformat()
attr_fn = lambda attr: sum(2 ** "RHS8DAdNTsLCOIEV.X.PU".index(a) for a in attr)
COLUMN_MAP = {
"Path" : conv(efu_column="Filename" , fn=pass_fn),
"Size" : conv(efu_column="Size" , fn=pass_fn),
"Modified" : conv(efu_column="Date Modified", fn=date_fn),
"Created" : conv(efu_column="Date Created" , fn=date_fn),
"Attributes": conv(efu_column="Attributes" , fn=attr_fn),
}
with (
open(SEVENZ_OUTPUT, "r", encoding="utf-8") as command_output,
open(EFU_FILENAME, "w", newline="", encoding="utf-8") as efu,
):
writer = DictWriter(efu, [column for (column, _fn) in COLUMN_MAP.values()])
writer.writeheader()
file_info = {}
for line in command_output:
line = line.rstrip("\n")
if line:
prop, value = line.split(" = ", 1)
if prop in COLUMN_MAP:
file_info[COLUMN_MAP[prop].column] = COLUMN_MAP[prop].fn(value)
else:
writer.writerow(file_info)
file_info.clear()

Convert the output of 7z l <FILE> -slt to the format of an EFU file list, to open in Everything or include in Everything's index

  • Try building a CLI with Click
  • Try building a GUI with Gooey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment