473,761 Members | 7,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

read list of dirnames and search for filenames

I cannot seem to get this to work. I am hyst trying to read in a list
of paths and see if the directory or any sub has a filename pattern.
Here is the code:

import os, sys
from path import path

myfile = open("boxids.tx t", "r")
for line in myfile.readline s():
d = path(line)
for f in d.walkfiles('*C onfig*.xml'):
print f

And here is my error:

Traceback (most recent call last):
File "Untitled.p y", line 21, in ?
for f in d.walkfiles('*C onfig*.xml'):
File "C:\Python24\Li b\site-packages\path.p y", line 460, in walkfiles
childList = self.listdir()
File "C:\Python24\Li b\site-packages\path.p y", line 328, in listdir
names = os.listdir(self )
WindowsError: [Errno 3] The system cannot find the path specified: u'X:
\\Instructions\ \97544546294\n/*.*'

What I don't get is if I just print the path it prints correctly, but
it keeps adding double "\"s to it.

I tried changing the backslashies to forward slashies and I get :
WindowsError: [Errno 3] The system cannot find the path specified:
u'X:/Instructions/97544546294\n/*.*'

help?

May 1 '07 #1
3 1406
fscked <fs*********@gm ail.comwrites:
I cannot seem to get this to work. I am hyst trying to read in a list
of paths and see if the directory or any sub has a filename pattern.
Here is the code:

import os, sys
from path import path

myfile = open("boxids.tx t", "r")
for line in myfile.readline s():
Instead of this:
d = path(line)
try this:

d = path(line.strip ())

``readlines`` doesn't remove trailing newline characters from string
for f in d.walkfiles('*C onfig*.xml'):
print f

And here is my error:

Traceback (most recent call last):
File "Untitled.p y", line 21, in ?
for f in d.walkfiles('*C onfig*.xml'):
File "C:\Python24\Li b\site-packages\path.p y", line 460, in walkfiles
childList = self.listdir()
File "C:\Python24\Li b\site-packages\path.p y", line 328, in listdir
names = os.listdir(self )
WindowsError: [Errno 3] The system cannot find the path specified: u'X:
\\Instructions\ \97544546294\n/*.*'
--
HTH,
Rob
May 1 '07 #2
Rob Wolfe <rw@smsnet.plwr ites:
fscked <fs*********@gm ail.comwrites:
>I cannot seem to get this to work. I am hyst trying to read in a list
of paths and see if the directory or any sub has a filename pattern.
Here is the code:

import os, sys
from path import path

myfile = open("boxids.tx t", "r")
for line in myfile.readline s():
And you don't need to use ``readlines`` at all.
This is enough:

for line in myfile:

--
HTH,
Rob
May 1 '07 #3
On May 1, 2:36 pm, Rob Wolfe <r...@smsnet.pl wrote:
Rob Wolfe <r...@smsnet.pl writes:
fscked <fsckedag...@gm ail.comwrites:
I cannot seem to get this to work. I am hyst trying to read in a list
of paths and see if the directory or any sub has a filename pattern.
Here is the code:
import os, sys
from path import path
myfile = open("boxids.tx t", "r")
for line in myfile.readline s():

And you don't need to use ``readlines`` at all.
This is enough:

for line in myfile:

--
HTH,
Rob
Worked well, thanks!

May 1 '07 #4

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

Similar topics

6
1495
by: Eric | last post by:
Pythonistas, I seem at a loss for a List Comprehension syntax that will do what I want. I have a list of string position spans: >>> breaks the first pair representing: someString
10
1405
by: jamesthiele.usenet | last post by:
I wrote this little piece of code to get a list of relative paths of all files in or below the current directory (*NIX): walkList = , x) for x in os.walk(".")] filenames = for dir, files in walkList: filenames.extend() for f in files]) It works fine, I don't need to change it, but I know there is a one liner list/generator comprehension to do this - I'm just not well
4
1778
by: Mullin Yu | last post by:
e.g. c:\test doc1.txt doc1.pdf doc2.txt doc2.pdf doc3.txt doc4.pdf doc5.txt doc5.pdf
2
8671
by: rbutch | last post by:
guys, i need a little help with this. this is working (well sort of) i get the info, but it's not moving to a new line as it iterates thru the array and all of the fields are like ONE HUGE LONG string 'declare an array Dim filenames() As String filenames = Directory.GetFiles("C:\Re_Class") Dim i, o As Integer Dim info As String
2
3731
by: Ministeyr | last post by:
Hello, os.walk doc: http://www.python.org/doc/2.4/lib/os-file-dir.html#l2h-1625 When walking top to bottom, it allows you to choose the directories you want to visit dynamically by changing the second parameter of the tuple (a list of directories). However, since it is a tuple, you cannot use "filter" on it, since it would mean reassigning it: for dir_tuple in os.walk('/home'):
10
1262
by: Abubakar | last post by:
Hi all, I'm using stl's list to store some file names. Its declared as: list < char * filenames; i enumerate the list by using: list < char * >::const_iterator filename; filename = filenames.begin();
14
2032
by: henrik.sorensen | last post by:
Hi List, I am looking for a way to do a case insensitive search for file names. Anybody have some hints ? thanks Henrik pl1gcc.sourceforge.net
0
2509
by: chongming | last post by:
Hi, i want to display all the filenames on browser. However i found that if there are many filenames in that folder, result will be it will display a long list of filenames on that browser. My question is how do i iterate the file names with 5 filenames on each page? I have manage to retrieve and display the filenames with the codes below. Can anyone help me or give advice on how to do the iteration? The codes are below and able to...
6
3161
by: kimiraikkonen | last post by:
Hello, I have a listbox and folder browser control. I need to display all .mp3 files' pathes into listbox. It was Ok with openfiledialog but how can list all .mp3 extension- having files into my listbox using folder browser control. A sample code would be great.
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10115
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...
0
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
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,...
1
7332
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
6609
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
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.