473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to print all files in a folder?

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.
Jul 17 '08 #1
5 16342
oler1s
671 Expert 512MB
My friend told me print in language doesn't mean print as in paper and ink.
Context matters (and you got it wrong) :) Your question is actually a tad vague.

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.
Jul 17 '08 #2
Check if this is the one u want to it has some basic things

Expand|Select|Wrap|Line Numbers
  1. import os,sys
  2.  
  3. contents=os.listdir('.') #contents of the current directory
  4. files =[]
  5. directory=[]
  6. for i in contents:
  7.     if os.path.isfile(i) == True :
  8.         files.append(i)
  9.     elif os.path.isdir(i) == True :
  10.         directory.append(i)
  11. #printing contents
  12. for j in files:
  13.     choice = raw_input("Dou you want to print file  %s (y/n): "%j)
  14.     if choice == 'y':
  15.         print "**************************"
  16.         print "Printing Files %s" %j
  17.         print "**************************"
  18.         fileobj = open(j,'r')
  19.         contents = fileobj.readlines()
  20.         for k in contents:
  21.             sys.stderr.write(k)
  22.     else:
  23.         pass
Jul 18 '08 #3
Sorry for being vague. Here's an example of what I want to do.

import pprint

pprint.pprint(open(r'c:\text\somefile.txt').readli nes())

And kaarthikeyapreyan. 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?
Jul 18 '08 #4
Laharl
849 Expert 512MB
To run a .py file, you use python <filename.py> <commandline arguments>.
Jul 18 '08 #5
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?
Hey i think u have to use the escape sequence for the backslash
("D:\\Modified")
Jul 22 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Julie Siebel | last post by:
Apologies...I'm sure this has been asked before, but I can't seem to come up with the correct Google search terms. While my problem is with stylesheets, the errors are being caused by my...
2
by: Glen | last post by:
As I understand it, when the first page of an application is accessed, all ASPX/ASCX/etc. files in the same folder are compiled using the JIT compiler. Is there a way to turn this feature off? ...
8
by: vinesh | last post by:
I have sample Asp.Net Web Application project. Let me know how to keep the files related to this project (like the webform.aspx, WebForm1.aspx.vb, WebForm1.aspx.resx) in a separate folder within a...
4
by: Pål Andreassen | last post by:
We are using themes (skin files and css files in the App_Theme) folder of a large web application. We are now implementing print functions on our pages. Earlier we've done this by having...
9
by: Scott M | last post by:
I'm printing a directory of about 500 multi-page tifs to a high speed printer and the spooler process is killing me!!! here is a little code..... Public Function PrintImage(ByVal...
1
by: sivakumarsubash | last post by:
I want to print all the files within the folder without opening the print dialog using javascript. the files may be any format, ie doc, xls, pdf, jpeg etc.. any help would be appreciated...
2
by: deve8ore | last post by:
Hello, I've already created a dropdown so an end user can pull up a specific file, and this will create a link to a variety of files (.xls, .txt., .pdf, ect...). I'd like to set about twenty...
3
by: nospam | last post by:
Hello, I have about two hundred individual RTF files to print from an XP host. Word 2000 doesn't seem to have this feature, so I'm looking for a way to print those RTF files from an ActivePython...
1
by: grego9 | last post by:
I am trying to write a macro that will print all files in a particular folder. The folder will always have the same name - but the number of files in that folder may differ. I simply want a macro...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.