Skip to content

Instantly share code, notes, and snippets.

@sagorbrur
Created December 3, 2019 03:56
Show Gist options
  • Select an option

  • Save sagorbrur/ce10c55cefd2dbc8d51d13b08a72ba62 to your computer and use it in GitHub Desktop.

Select an option

Save sagorbrur/ce10c55cefd2dbc8d51d13b08a72ba62 to your computer and use it in GitHub Desktop.
import os
from tqdm import tqdm
count = 0
for root, dirs, files in tqdm(os.walk("/path")):
for file in files:
if file.endswith(".txt"):
# print(file)
filename = "files/text_{}".format(count)
output = open(filename, "w")
path = os.path.join(root, file)
# print(path)
text = open(path, "r").read()
output.write(text)
count+=1
output.close()
print("Total text file found: ", count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment