Skip to content

Instantly share code, notes, and snippets.

@StepMaher
Last active October 2, 2016 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StepMaher/2152ea7338e13a08131af00e03fabd2f to your computer and use it in GitHub Desktop.
Save StepMaher/2152ea7338e13a08131af00e03fabd2f to your computer and use it in GitHub Desktop.
"""
Lists content of the history folder.
Outputs:
full_file: Full file paths for each file.
file_names: File name and extensions for each file.
"""
# Import libraries
import os
# Declare empty list
file_names = []
full_file = []
# Get directory
path = os.path.split(ghdoc.Path)
dir = path[0] + "\out" # Here I'm declaring a specific folder that contains the files I want to operate on
full_path = os.path.join(dir, '')
# Get directory contents
contents = os.listdir(dir)
# Grab files and add to empty lists
for file in contents:
if file.endswith(".txt"): # you can use any file extension here
file_names.append(file)
file_names.sort()
full_file.append(full_path + file)
# Grab empty files and delete if prompted
for fp in full_file:
if clear:
if os.stat(fp).st_size == 0:
try:
if os.path.isfile(fp):
os.unlink(fp)
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment