473,806 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading from list with paths

Hello,

I would like to read and print files, of which the complete filepaths
are
mentioned in another textfile. In this textfile (list.txt) are for
example the following paths:

/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f 01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPs eudo_f01.TextGr id
/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_ f01.TextGrid

I know how to open and read one file in my current directory,
but after trying to find this out my self, I give up...

I already got one answer for this question, but it did not work

Thanks a lot

Antar2

Jun 27 '08 #1
5 1588
Le Wednesday 25 June 2008 20:59:38 antar2, vous avez écrit*:
Hello,

I would like to read and print files, of which the complete filepaths
are
mentioned in another textfile. In this textfile (list.txt) are for
example the following paths:

/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f 01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPs eudo_f01.TextGr id
/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_ f01.TextGrid

I know how to open and read one file in my current directory,
but after trying to find this out my self, I give up...

I already got one answer for this question, but it did not work
What's the problem exactly ? If you already know how to read a file you have
all what you need:

f_list = open('list.txt' )
for filename in f_list :
f = open(filename)
print f.read()
f.close()
f_list.close()

If you get an error, please post the full error message with the backtrace.

--
Cédric Lucantis
Jun 27 '08 #2
On 25 juin, 20:59, antar2 <desoth...@yaho o.comwrote:
Hello,
(snip repost of the very same question)
I already got one answer for this question, but it did not work
For which definition of "did not work" ? How is your code ? What did
you expect, and what did you get ? Sorry to ask these questions, but
my crystal ball is currently down for maintainance...

Jun 27 '08 #3
Lie
On Jun 26, 1:59*am, antar2 <desoth...@yaho o.comwrote:
Hello,

I would like to *read and print files, of which the complete filepaths
are
*mentioned in another textfile. In this textfile (list.txt) *are for
*example the following paths:

/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f 01.TextGrid
*/data/chorec/chorec-nieuw/s01/S01C001M1/
*S01C001M1_1LGP seudo_f01.TextG rid
*/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_ f01.TextGrid

I know how to open and read one file in my current directory,
*but after trying to find this out my self, I give up...
Is this Window's path or Unix-like's path. In Windows, path is
generally like this:
"folder\\data.t xt" OR r"folder\data.t xt"
because Windows use backslash as its path separator

In Unix-like OS (Unix, Linux, OSX), they use forward slash.

In general, Windows (Explorer) doesn't care whether you used backslash
or forward slash, but I'm not sure if we can use forwardslash in
Python.

I already got one answer for this question, but it did not work
It didn't work... how? Any error message? or what's the content of the
name that should be file object.
>
Thanks a lot

Antar2
Jun 27 '08 #4

antar2 wrote:
Hello,

I would like to read and print files, of which the complete filepaths
are
mentioned in another textfile. In this textfile (list.txt) are for
example the following paths:

/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f 01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPs eudo_f01.TextGr id
/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_ f01.TextGrid

I know how to open and read one file in my current directory,
but after trying to find this out my self, I give up...

I already got one answer for this question, but it did not work

Thanks a lot

Antar2

--
http://mail.python.org/mailman/listinfo/python-list
---------------------------------
I think what you want is more like:

contents of a file named printthem.py
......
import os

p = open('list.txt' )
for vpath in p:
for f in os.listdir(vpat h):
print '\n\tContents of:',vpath+'/'+f
f = open(vpath+'/'+f)
print f.read()
f.close()
print '\n\t\t\t\tEND OF FILE\x0C'
p.close()
print "All Done. Is there any paper left?"
......

usage: python printthem.py >/dev/lp0 Unix
python printthem.py prn: Microsoft

On Microsoft use '\\' in place of '/' following each vpath above
The \x0C is Ctrl-L aka: ff or FormFeed
norseman
Jun 27 '08 #5
On Jun 25, 10:00*pm, norseman <norse...@hughe s.netwrote:
antar2 wrote:
Hello,
I would like to *read and print files, of which the complete filepaths
are
*mentioned in another textfile. In this textfile (list.txt) *are for
*example the following paths:
/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f 01.TextGrid
*/data/chorec/chorec-nieuw/s01/S01C001M1/
*S01C001M1_1LGP seudo_f01.TextG rid
*/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_ f01.TextGrid
I know how to open and read one file in my current directory,
*but after trying to find this out my self, I give up...
I already got one answer for this question, but it did not work
Thanks a lot
Antar2
--
http://mail.python.org/mailman/listinfo/python-list

---------------------------------
I think what you want is more like:

contents of a file named printthem.py
.....
import os

p = open('list.txt' )
for vpath in p:
* *for f in os.listdir(vpat h):
* * *print '\n\tContents of:',vpath+'/'+f
* * *f = open(vpath+'/'+f)
* * *print f.read()
* * *f.close()
* * *print '\n\t\t\t\tEND OF FILE\x0C'
p.close()
print "All Done. Is there any paper left?"
.....

usage: python printthem.py >/dev/lp0 * * * * Unix
* * * * python printthem.py prn: * * * * * Microsoft

On Microsoft use '\\' in place of '/' following each vpath above
The \x0C is Ctrl-L * aka: ff or FormFeed

norseman
FYI, Python also understands '\f' ('\x0c').

Interestingly, print repr('\a\b\f\n\ r\t\v') gives '\x07\x08\x0c\n \r\t
\x0b'. Is that because '\n', '\r' and '\t' occur so often that it was
decided that they should be treated specially?
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2067
by: jnc | last post by:
Hi, I was wondering if anybody had any pointers on the following: I need to write some code which takes a list of file paths and transforms them into a treeview which shows the directory structure of the file paths. Cheers.....Jim
4
2012
by: James Kunicki | last post by:
Hello, I would like to know if anyone as found a way to list a image next to a list box to indicate what type of drive (local or network) and a folder I would like to present in a user interface like the OpenFileDialog that has a pulldown(at the top of the dialog) to allow a user to navigate a directory/folder selection.
2
4173
by: Stu | last post by:
Hi, I am writing a windows forms app that needs to list all the virtual servers and their respective log file paths. The IIS6 metabse is nice and easy as it is XML. Is there any way to reading these details from the IIS5 metabase - which appears to be a binary format? Thanks in advance,
3
4662
by: tigrrgrr42 | last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am currently bringing them from a byte array into a temp file to pop into word and make word do its thing as a com object. Is it possible to go straight from a byte array to document in word instead of a temp file? Also is there a way to change the save behaviour to notify my app to pickup a binary copy of the file or stream to save back to the sql db. Thanks in...
1
324
by: Vesa Leppanen | last post by:
Hi, I am new in python-list and quite new in Python programming as well. I am working mainly with GIS and using Esri's geoprocessing tools. I want to use .ini file to set the parameters, especially paths, in my project. PythonWin 2.1. is my version. Why do I get the default back in the case below? Any way around?
2
3793
by: dave6502 | last post by:
Struggling newbe here, some of my #includes work, some dont. Is it possible to list the include path ? (in BASH), I have looked at the environmental variables (loads of them) but cannot find a reference. Cheers Dave
1
178
by: antar2 | last post by:
Hello, Suppose this is a stupid question, but as a python beginner I encounter a lot of obstacles... so I would be very grateful with some help for following question: I would like to read files, of which the complete filepaths are mentioned in another textfile. In this textfile (list.txt) are for example the following paths:
5
2169
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could be 1 of these or 100....quantity can change***** </Tabs>
0
1366
by: drewgy | last post by:
Can anyone tell me how to get a list of full UNC paths for all printers on a network? I have tried using WMI but the following code only gives me a list of local printers, and doesn't give me the fully qualified paths. private void GetNetworkPrinters() { try { string strQuery = "SELECT * FROM Win32_Printer";
0
10623
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10373
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.