Last active
October 2, 2016 14:42
-
-
Save StepMaher/2152ea7338e13a08131af00e03fabd2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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