-2

I am trying to collect every txt file from my computer and write it into the terminal when I run the script. I do not know how to do it. Is there a way to read every txt file in the computer then print the contents? (not a certain folder or directory).

ThatSpy
  • 1
  • 1
  • What have you tried so far? What does "collect" mean? What is the definition of a text file? Do you mean display or actually print it? On linux `find / -name \*.txt| xargs cat` would be the way I do it. – Allan Wind Dec 29 '20 at 04:34

1 Answers1

0

In Python, the glob module would give you a list of filenames matching a given string. In your case, glob.glob('dir/*.txt') would give you a list of filenames in directory dir that end in .txt. You can then open each file and print() it to the terminal. Depending on your OS, you might be able to do it in your terminal without writing a separate script.

Chris M-B
  • 62
  • 8