Reading and writing files in order - Python
Sorry Quite new to python as a language.
So I have 5 files lets say. item1.txt, item2.txt, item3.txt, item4.txt and
item5.txt. I am trying to call on the directory so that it picks out the
first file (item1.txt) and print its content, then when I call on that
function again (item2.txt) and its content within the file is printed...
then (item3.txt) and then (item4.txt).
The order is important and the system must know what file has been printed
so that the next file in line can print after the first eg. the content of
item1.txt prints first then item2.txt.
Trying to use:
for infile in sorted(glob.glob('*.txt')):
print "Current File Being Processed is: " + infile
But the problem is the directory needs to be added and the system needs to
know what file and its content was printed before it.
Sorry if this was confusing.
Help appreciated.
No comments:
Post a Comment