Skip to content

Instantly share code, notes, and snippets.

@reee
Last active July 22, 2023 03:23
Show Gist options
  • Save reee/74c459b9ffcc954da3ddaeb83da9b771 to your computer and use it in GitHub Desktop.
Save reee/74c459b9ffcc954da3ddaeb83da9b771 to your computer and use it in GitHub Desktop.
open a random file in the dictionary
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import random
import pickle
import configparser
import pyperclip
configParser = configparser.RawConfigParser()
configFilePath = r'config.txt'
configParser.read(configFilePath, encoding='utf-8')
rootPath = configParser.get('config', 'rootPath')
types = tuple(configParser.get('config', 'Types').split(','))
def getFileList(path, types):
itemlist = []
if not os.path.isfile('db-file'):
for root, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith(types):
itemlist.append(os.path.join(root, filename))
with open('db-file', 'wb') as fp:
pickle.dump(itemlist, fp)
else:
with open ('db-file', 'rb') as fp:
itemlist = pickle.load(fp)
return itemlist
l = getFileList(rootPath, types)
f = random.choice(l)
pyperclip.copy("DEL " + "\"" + f + "\"")
os.startfile(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment