Hello. I was wondering how to print all the files in a folder. If possible, could it be like Python prints one file and waits for a confirmation and then moves to the next? By the way, by print, I don't mean like printer paper stuff. I mean by Python writes the stuff out in the Command Prompt thing. My friend told me print in language doesn't mean print as in paper and ink. I use Windows2k and Python 2.5. Thanks in advanced.
How to print all files in a folder?
Collapse
X
-
How to print all files in a folder?
-
My friend told me print in language doesn't mean print as in paper and ink.
Are you asking if you want dump the contents of all the file in a folder to standard output? That is, dump the output of one file to standard output, wait for confirmation, dump the second one, and so on?
I was thinking, "too bad you're not on a *NIX, you could just write a small shell script to repeatedly cat all the files in a directory". You can actually get cat for Windows, as there is a windows port.
In any case, what you probably want to do is use Python to get a list of all the files in a directory. Look at Python docs and more Googling for examples.
You can then for each file repeatedly extract it line by line and then dump the line to output. Or call cat on said file. -
Check if this is the one u want to it has some basic things
Code:import os,sys contents=os.listdir('.') #contents of the current directory files =[] directory=[] for i in contents: if os.path.isfile(i) == True : files.append(i) elif os.path.isdir(i) == True : directory.append(i) #printing contents for j in files: choice = raw_input("Dou you want to print file %s (y/n): "%j) if choice == 'y': print "**************************" print "Printing Files %s" %j print "**************************" fileobj = open(j,'r') contents = fileobj.readlines() for k in contents: sys.stderr.write(k) else: pass
Comment
-
Sorry for being vague. Here's an example of what I want to do.
import pprint
pprint.pprint(o pen(r'c:\text\s omefile.txt').r eadlines())
And kaarthikeyaprey an. I think you have it but I don't know how to execute it. I put all of that into a .py file and then what do I do. I also tried typing it out in the Command Line but at the end I just get the ... and nothing happens. Was the directory name the only thing I had to add?
EDIT: Ok. I made a mistake by changing the ('.') to the folder I wanted to do. Example: ('D:\Modified') . It works but it does my python folder. How do I do it so it does another folder?Comment
-
Originally posted by surreptitiousEDIT: Ok. I made a mistake by changing the ('.') to the folder I wanted to do. Example: ('D:\Modified') . It works but it does my python folder. How do I do it so it does another folder?
("D:\\Modified" )Comment
Comment