Re: os.walk the apostrophe and unicode

2017-06-25 Thread Rod Person
On Sun, 25 Jun 2017 08:18:45 -0600 Michael Torrie wrote: > On 06/25/2017 06:19 AM, Rod Person wrote: > > But doing a simple ls of that directory show it is unicode but the > > replacement of the offending character. > > > > http://rodperson.com/graphics/uc/ls.png > > Now that is really strang

Re: os.walk the apostrophe and unicode

2017-06-25 Thread Peter Otten
Rod Person wrote: > Ok...so after reading all the replies in the thread, I thought I would > be easier to send a general reply and include some links to screenshots. > > As Peter mention, the logic thing to do would be to fix the file name > to what I actually thought it was and if this was for w

Re: os.walk the apostrophe and unicode

2017-06-25 Thread Michael Torrie
On 06/25/2017 06:19 AM, Rod Person wrote: > But doing a simple ls of that directory show it is unicode but the > replacement of the offending character. > > http://rodperson.com/graphics/uc/ls.png Now that is really strange. Your OS seems to not recognize that the filename is in UTF-8. I suspec

Re: os.walk the apostrophe and unicode

2017-06-25 Thread Rod Person
Ok...so after reading all the replies in the thread, I thought I would be easier to send a general reply and include some links to screenshots. As Peter mention, the logic thing to do would be to fix the file name to what I actually thought it was and if this was for work that probably what I woul

Re: os.walk the apostrophe and unicode

2017-06-25 Thread alister
On Sun, 25 Jun 2017 02:23:15 -0700, wxjmfauth wrote: > Le samedi 24 juin 2017 21:10:47 UTC+2, alister a écrit : >> On Sat, 24 Jun 2017 14:57:21 -0400, Rod Person wrote: >> >> > \xe2\x80\x99, >> >> because the file name has been created using "Right single quote" >> instead of apostrophe, the gly

Re: os.walk the apostrophe and unicode

2017-06-25 Thread Peter Otten
Steve D'Aprano wrote: > On Sun, 25 Jun 2017 04:57 pm, Peter Otten wrote: >> if everything worked correctly? Though I don't understand why the OP >> doesn't see >> >> '06 - Toddâ\x80\x99s Song (Post-Spiderland Song in Progress).flac' >> >> which is the repr() that I get. > > That's mojibake and

Re: os.walk the apostrophe and unicode

2017-06-25 Thread Steve D'Aprano
On Sun, 25 Jun 2017 04:57 pm, Peter Otten wrote: > Steve D'Aprano wrote: > >> On Sun, 25 Jun 2017 07:17 am, Peter Otten wrote: >> >>> Then I'd fix the name manually... >> >> The file name isn't broken. >> >> >> What's broken is parts of the OP's code which assumes that non-ASCII file >> names

Re: os.walk the apostrophe and unicode

2017-06-25 Thread Peter Otten
Steve D'Aprano wrote: > On Sun, 25 Jun 2017 07:17 am, Peter Otten wrote: > >> Then I'd fix the name manually... > > The file name isn't broken. > > > What's broken is parts of the OP's code which assumes that non-ASCII file > names are broken... Hm, the OP says '06 - Todd\xe2\x80\x99s Song (

Re: os.walk the apostrophe and unicode

2017-06-24 Thread Steve D'Aprano
On Sun, 25 Jun 2017 07:17 am, Peter Otten wrote: > Then I'd fix the name manually... The file name isn't broken. What's broken is parts of the OP's code which assumes that non-ASCII file names are broken... -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure e

Re: os.walk the apostrophe and unicode

2017-06-24 Thread Peter Otten
Rod Person wrote: > On Sat, 24 Jun 2017 21:28:45 +0200 > Peter Otten <__pete...@web.de> wrote: > >> Rod Person wrote: >> >> > Hi, >> > >> > I'm working on a program that will walk a file system and clean the >> > id3 tags of mp3 and flac files, everything is working great until >> > the follow

Re: os.walk the apostrophe and unicode

2017-06-24 Thread MRAB
On 2017-06-24 20:47, Rod Person wrote: On Sat, 24 Jun 2017 13:28:55 -0600 Michael Torrie wrote: On 06/24/2017 12:57 PM, Rod Person wrote: > Hi, > > I'm working on a program that will walk a file system and clean the > id3 tags of mp3 and flac files, everything is working great until > the fo

Re: os.walk the apostrophe and unicode

2017-06-24 Thread Andre Müller
Can os.fsencode and os.fsdecode help? I've seen it somewhere. I've never used it. To fix encodings, sometimes I use the module ftfy Greetings Andre -- https://mail.python.org/mailman/listinfo/python-list

Re: os.walk the apostrophe and unicode

2017-06-24 Thread Rod Person
On Sat, 24 Jun 2017 13:28:55 -0600 Michael Torrie wrote: > On 06/24/2017 12:57 PM, Rod Person wrote: > > Hi, > > > > I'm working on a program that will walk a file system and clean the > > id3 tags of mp3 and flac files, everything is working great until > > the follow file is found > > > > '06

Re: os.walk the apostrophe and unicode

2017-06-24 Thread Rod Person
On Sat, 24 Jun 2017 21:28:45 +0200 Peter Otten <__pete...@web.de> wrote: > Rod Person wrote: > > > Hi, > > > > I'm working on a program that will walk a file system and clean the > > id3 tags of mp3 and flac files, everything is working great until > > the follow file is found > > > > '06 - Tod

Re: os.walk the apostrophe and unicode

2017-06-24 Thread Peter Otten
Rod Person wrote: > Hi, > > I'm working on a program that will walk a file system and clean the id3 > tags of mp3 and flac files, everything is working great until the > follow file is found > > '06 - Todd's Song (Post-Spiderland Song in Progress).flac' > > for some reason that I can't understa

Re: os.walk the apostrophe and unicode

2017-06-24 Thread Michael Torrie
On 06/24/2017 12:57 PM, Rod Person wrote: > Hi, > > I'm working on a program that will walk a file system and clean the id3 > tags of mp3 and flac files, everything is working great until the > follow file is found > > '06 - Todd's Song (Post-Spiderland Song in Progress).flac' > > for some reaso

Re: os.walk the apostrophe and unicode

2017-06-24 Thread MRAB
On 2017-06-24 19:57, Rod Person wrote: Hi, I'm working on a program that will walk a file system and clean the id3 tags of mp3 and flac files, everything is working great until the follow file is found '06 - Todd's Song (Post-Spiderland Song in Progress).flac' for some reason that I can't unde

Re: os.walk the apostrophe and unicode

2017-06-24 Thread John Ladasky
On Saturday, June 24, 2017 at 12:07:05 PM UTC-7, Rod Person wrote: > Hi, > > I'm working on a program that will walk a file system and clean the id3 > tags of mp3 and flac files, everything is working great until the > follow file is found > > '06 - Todd's Song (Post-Spiderland Song in Progress).

Re: os.walk the apostrophe and unicode

2017-06-24 Thread alister
On Sat, 24 Jun 2017 14:57:21 -0400, Rod Person wrote: > \xe2\x80\x99, because the file name has been created using "Right single quote" instead of apostrophe, the glyphs look identical in many fonts. -- "If you understand what you're doing, you're not learning anything." --

Re: os.walk/list

2011-03-21 Thread Peter Otten
ecu_jon wrote: > yes i agree breaking stuff into smaller chunks is a good way to do it. > even were i to do something like > > def safe_copy() > f1=file(files ,'rb') > f2 = file(os.path.join(currentdir,fname,files)) > truth = md5.new(f1.read()).digest() == > md5.new(f2.read()).dig

Re: os.walk/list

2011-03-20 Thread ecu_jon
yes i agree breaking stuff into smaller chunks is a good way to do it. even were i to do something like def safe_copy() f1=file(files ,'rb') f2 = file(os.path.join(currentdir,fname,files)) truth = md5.new(f1.read()).digest() == md5.new(f2.read()).digest() if truth == 0:

Re: os.walk/list

2011-03-20 Thread Peter Otten
ecu_jon wrote: > so i am trying to add md5 checksum calc to my file copy stuff, to make > sure the source and dest. are same file. > i implemented it fine with the single file copy part. something like : > for files in sourcepath: > f1=file(files ,'rb') > try: > shutil.

Re: os.walk/list

2011-03-19 Thread Dan Stromberg
You're not really supposed to call into the md5 module directly anymore; you might use hashlib instead. But actually, using a cryptographic hash doesn't really help comparing just one pair of files; it's more certain to do a block by block comparison, and the I/O time is roughly the same - actuall

Re: os.walk restart

2010-03-31 Thread Piet van Oostrum
You have no guarantee that on the next run the directories will be visited in the same order as in the first run (this could depend on the filesystem). So then remembering a last directory won't do it. You could write each completed directory name to a file, and then on the second run check whether

Re: os.walk restart

2010-03-18 Thread Tim Chase
Steve Howell wrote: If that's the case, then you might be able to get away with just leaving some kind of breadcrumbs whenever you've successfully processed a directory or a file, Unless you're indexing a read-only device (whether hardware read-only like a CD, or permission-wise read-only like

Re: os.walk restart

2010-03-17 Thread Steven D'Aprano
On Wed, 17 Mar 2010 20:08:48 -0700, alex23 wrote: > Steven D'Aprano wrote: >> # Untested >> last_visited = open("last_visited.txt", 'r').read() >> for root, dirs, files in os.walk(last_visited or basedir): >>      open("last_visited.txt", 'w').write(root) run program > > Wouldn't this only walk

Re: os.walk restart

2010-03-17 Thread Steve Howell
On Mar 17, 3:04 pm, Keir Vaughan-taylor wrote: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): >     run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of

Re: os.walk restart

2010-03-17 Thread MRAB
Keir Vaughan-taylor wrote: I am traversing a large set of directories using for root, dirs, files in os.walk(basedir): run program Being a huge directory set the traversal is taking days to do a traversal. Sometimes it is the case there is a crash because of a programming error. As each dir

Re: os.walk restart

2010-03-17 Thread alex23
Steven D'Aprano wrote: > # Untested > last_visited = open("last_visited.txt", 'r').read() > for root, dirs, files in os.walk(last_visited or basedir): >      open("last_visited.txt", 'w').write(root) >      run program Wouldn't this only walk the directory the exception occured in and not the rem

Re: os.walk restart

2010-03-17 Thread Gabriel Genellina
En Wed, 17 Mar 2010 19:04:14 -0300, Keir Vaughan-taylor escribió: I am traversing a large set of directories using for root, dirs, files in os.walk(basedir): run program Being a huge directory set the traversal is taking days to do a traversal. Sometimes it is the case there is a crash

Re: os.walk restart

2010-03-17 Thread Steven D'Aprano
On Wed, 17 Mar 2010 15:04:14 -0700, Keir Vaughan-taylor wrote: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is

Re: os.walk()

2009-08-06 Thread Chris Rebert
> On Tue, Aug 4, 2009 at 10:48 PM, Chris Rebert wrote: >> On Tue, Aug 4, 2009 at 7:06 PM, Michael Savarese wrote: >> > Greetings >> > Python newbie here, and thanks to all who have helped me previously. >> > Is there a way of grabbing file attributes while traversing with os.walk()? >> > It would

Re: os.walk()

2009-08-04 Thread Chris Rebert
On Tue, Aug 4, 2009 at 7:06 PM, Michael Savarese wrote: > Greetings > Python newbie here, and thanks to all who have helped me previously. > Is there a way of grabbing file attributes while traversing with os.walk()? > It would be advantageous to have date modified and file size along with the > fi

Re: os.walk and os.listdir problems python 3.0+

2009-06-27 Thread Gabriel Genellina
En Thu, 25 Jun 2009 11:15:15 -0300, Amos Anderson escribió: Thank you. That works very well when writing to a text file but what is the equivalent when writing the information to stdout using print? See this recent post: http://comments.gmane.org/gmane.comp.python.general/627850 -- Gabri

Re: os.walk and os.listdir problems python 3.0+

2009-06-25 Thread Amos Anderson
Thank you. That works very well when writing to a text file but what is the equivalent when writing the information to stdout using print? Sorry when I originally replied I sent it directly and it didn't go to the list. On Thu, Jun 25, 2009 at 12:57 AM, Mark Tolonen > wrote: > > "Amos Anderson"

Re: os.walk and os.listdir problems python 3.0+

2009-06-24 Thread Mark Tolonen
"Amos Anderson" wrote in message news:a073a9cf0906242007k5067314dn8e9d7b1c6da62...@mail.gmail.com... I've run into a bit of an issue iterating through files in python 3.0 and 3.1rc2. When it comes to a files with '\u200b' in the file name it gives the error... Traceback (most recent call la

Re: os.walk question

2008-07-26 Thread Terry Reedy
Eric Wertman wrote: I do this, mabye a no-no? It is a roundabout way to do multiple assignment: import os for root,dirs,files in os.walk(dir) : break root,dirs,files = os.walk(dir).next #2.x root,dirs,files = next(os.walk(dir))#3.x -- http://mail.python.org/mailman/listinfo/python-lis

Re: os.walk question

2008-07-26 Thread Eric Wertman
I do this, mabye a no-no? import os for root,dirs,files in os.walk(dir) : break -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk question

2008-07-25 Thread Fredrik Lundh
Lawrence D'Oliveiro wrote: Won't that return any subdirectories as well as files? sure, as was discussed in this very thread two days ago. -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk question

2008-07-24 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Fredrik Lundh wrote: > Lanny wrote: > >> How would one make a list of the files in the top directory >> using os.walk. >> >> I need to pick a random file from said list. > > if you want a list of files from a single directory, use listdir, not > walk: > >

Re: os.walk question

2008-07-23 Thread B
Lanny wrote: How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. Thanks. -- Posted on news://freenews.netfront.net - Complaints to [EMAIL PROTECTED] -- how about: import os x = os.walk('/') (root,dirs,files) = x.next

Re: os.walk question

2008-07-23 Thread alex23
On Jul 23, 10:26 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >      random.choice(filter(os.path.isfile, glob.glob("/*"))) > > isn't that bad, though. I'll agree to that. -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk question

2008-07-23 Thread alex23
On Jul 23, 10:11 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > import glob > random.choice([f for f in glob.glob(root, "*")]) glob.glob only accepts one argument though, did you mean root + "*"? It also returns folders as well as files, though, and the list comprehension is not necessary given it

Re: os.walk question

2008-07-23 Thread Fredrik Lundh
alex23 wrote: if you want a list of files from a single directory, use listdir, not walk: >>> import os, random >>> random.choice(os.listdir("/")) 'python25' This will include folders as well, though, which isn't what the OP asked for. as illustrated by my example (cut and

Re: os.walk question

2008-07-23 Thread Larry Bates
Fredrik Lundh wrote: Lanny wrote: How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. if you want a list of files from a single directory, use listdir, not walk: >>> import os, random >>> random.choice(os.listdir(

Re: os.walk question

2008-07-23 Thread alex23
On Jul 23, 5:22 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > if you want a list of files from a single directory, use listdir, not walk: > >       >>> import os, random >       >>> random.choice(os.listdir("/")) >       'python25' This will include folders as well, though, which isn't what the O

Re: os.walk question

2008-07-23 Thread Fredrik Lundh
Lanny wrote: How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. if you want a list of files from a single directory, use listdir, not walk: >>> import os, random >>> random.choice(os.listdir("/")) 'python25'

Re: os.walk question

2008-07-23 Thread alex23
On Jul 24, 11:52 am, "Lanny" <[EMAIL PROTECTED]> wrote: > How would one make a list of the files in the top directory > using os.walk. > > I need to pick a random file from said list. So you -only- want the files from one directory? Try: _, _, files = os.walk('/top/folder/here').next() The singl

Re: os.walk Value Error?

2008-06-15 Thread Gabriel Genellina
En Sat, 14 Jun 2008 19:06:16 -0300, <[EMAIL PROTECTED]> escribió: > I'm using os.walk as follows: > > (basedir, pathnames, files) = os.walk("results", topdown=True) > > and I'm getting the error: > > ValueError: too many values to unpack > >> From my googling, that means: > > This is the standard

Re: os.walk Value Error?

2008-06-14 Thread tdahsu
On Jun 14, 7:11 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hi, > > > I'm using os.walk as follows: > > > (basedir, pathnames, files) = os.walk("results", topdown=True) > > > and I'm getting the error: > > > ValueError: too many values to unpack > > > From my googling,

Re: os.walk Value Error?

2008-06-14 Thread Christian Heimes
[EMAIL PROTECTED] wrote: > Is there any other reason I might get that error? Yes, you are using it the wrong way. The correct way is for root, dirs, files in os.walk(path): do something os.walk returns an iterator which yields root, dirs and files for each iteration. Christian -- http://ma

Re: os.walk Value Error?

2008-06-14 Thread Larry Bates
[EMAIL PROTECTED] wrote: Hi, I'm using os.walk as follows: (basedir, pathnames, files) = os.walk("results", topdown=True) and I'm getting the error: ValueError: too many values to unpack From my googling, that means: This is the standard message when Python tries to unpack a tuple into fewe

Re: os.walk and recursive deletion

2007-10-28 Thread Martin Marcher
27 Oct 2007 17:38:10 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>: > On Sat, 27 Oct 2007 18:07:44 +0200, Martin Marcher wrote: > > I'm playing around with os.walk and I made up del_tree(path) which I > > think is correct (in terms of the algorithm, but not as python wants > > it :)). > > It's

Re: os.walk and recursive deletion

2007-10-27 Thread Marc 'BlackJack' Rintsch
On Sat, 27 Oct 2007 18:07:44 +0200, Martin Marcher wrote: > Hello, > > I'm playing around with os.walk and I made up del_tree(path) which I > think is correct (in terms of the algorithm, but not as python wants > it :)). It's not correct in terms of the algorithm if you take the algorithm of `os

Re: os.walk and recursive deletion

2007-10-27 Thread Peter Otten
Martin Marcher wrote: > Hello, > > I'm playing around with os.walk and I made up del_tree(path) which I > think is correct (in terms of the algorithm, but not as python wants > it :)). > > As soon as some directory is deleted the iterator of os.walk chokes. > OK that is somehow clear to me as it

Re: os.walk return hex excapes

2006-11-28 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Alex S wrote: > os.walk return hex excape sequence inside a files name, and when i try > to feed it back to os.remove i get > > OSError: [Errno 22] Invalid argument: > 'C:\\Temp\\?p?\xbfS\xbf\xac?G\xaba ACDSee \xbb?a??n a???\xac\xb5\xbfn.exe' There is no hex escape in th

Re: os.walk return hex excapes

2006-11-28 Thread Leo Kislov
Alex S wrote: > Hi, > os.walk return hex excape sequence inside a files name, and when i try > to feed it back to os.remove i get > > OSError: [Errno 22] Invalid argument: > 'C:\\Temp\\?p?\xbfS\xbf\xac?G\xaba ACDSee \xbb?a??n a???\xac\xb5\xbfn.exe' It's not escape sequences that are the problem bu

Re: os.walk trouble

2006-06-01 Thread The Prophet
Kent Johnson wrote: > The Prophet wrote: > > As my first Python script, I am trying to make a program that recurses > > a directory searching for files whose names match a pattern. > > If your patterns are simple (supported by fnmatch), the path module > makes this very easy: > import path > for f

Re: os.walk trouble

2006-06-01 Thread Kent Johnson
The Prophet wrote: > As my first Python script, I am trying to make a program that recurses > a directory searching for files whose names match a pattern. If your patterns are simple (supported by fnmatch), the path module makes this very easy: import path for f in path.path(dirname).walkfiles('

Re: os.walk trouble

2006-06-01 Thread BartlebyScrivener
> As my first Python script, I am trying to make a program that recurses > a directory searching for files whose names match a pattern. I have a > basic idea of what the regexp would look like You probably don't need regexp for this, just use the fnmatch module http://docs.python.org/lib/module-f

Re: os.walk trouble

2006-06-01 Thread BartlebyScrivener
>> root, dirs, files = os.walk(dirname) If you want to do it this way, you need to stop it after the first one: root, dirs, files = os.walk(dirname).next() print root print dirs print files see this thread http://tinyurl.com/rmyo4 -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk trouble

2006-06-01 Thread BartlebyScrivener
Neat. And looks better, at least on my machine, if you had a tab or two and an extra \n after the dirs. rick for filepath, dirs, files in os.walk(root): #you're looking at the "dirs" and "files" in filepath print "Currently in %s" % filepath print "\t[Directories in %s]" %

Re: os.walk trouble

2006-06-01 Thread Tim Chase
> but I am stuck with incorrect understanding of > os.walk. I've tried: > > root, dirs, files = os.walk(dirname) os.walk returns an iteratable sequence of those tuples. Thus, you want to have for filepath, dirs, files in os.walk(dirname): #you're looking at the "dirs" and "files" in fi

Re: os.walk() dirs and files

2006-02-08 Thread rtilley
George Sakkis wrote: > Or a bit more efficiently (no need to allocate a new list for storing > files+dirs): > > from itertools import chain > for root, dirs, files in os.walk(path): > for fs_object in chain(files,dirs): > ADD fs_object to dictionary I like that! itertools is

Re: os.walk() dirs and files

2006-02-08 Thread Tim Peters
[rtilley] > When working with file and dir info recursively on Windows XP. I'm going > about it like this: > > for root, dirs, files in os.walk(path): > for f in files: > ADD F to dictionary > for d in dirs: > ADD D to dictionary > > Is it possible to do something such a

Re: os.walk() dirs and files

2006-02-08 Thread George Sakkis
rtilley wrote: > Duncan Booth wrote: > >> How about just concatentating the two lists: >> >>> for root, dirs, files in os.walk(path): >> >>for fs_object in files + dirs: >> >>> ADD fs_object to dictionary > > > Thank you Duncan! that solves the problem perfectly! Or a bit more effi

Re: os.walk() dirs and files

2006-02-08 Thread Duncan Booth
rtilley wrote: > Just to clarify. In this particular case, I do not need to differentiate > between files and dirs... so would it be possible to do something such > as this: > How about just concatentating the two lists: > for root, dirs, files in os.walk(path): > for fs_object in files,

Re: os.walk() dirs and files

2006-02-08 Thread rtilley
rtilley wrote: > Hello, > > When working with file and dir info recursively on Windows XP. I'm going > about it like this: > > for root, dirs, files in os.walk(path): > for f in files: > ADD F to dictionary > for d in dirs: > ADD D to dictionary > > Is it possible to do

Re: os.walk() dirs and files

2006-02-08 Thread rtilley
Duncan Booth wrote: > How about just concatentating the two lists: > >>for root, dirs, files in os.walk(path): >for fs_object in files + dirs: >> ADD fs_object to dictionary Thank you Duncan! that solves the problem perfectly! -- http://mail.python.org/mailman/listinfo/python-li

Re: os.walk(entire filesystem)

2005-03-11 Thread Simon Brunning
On Thu, 10 Mar 2005 20:11:10 +0100, Uwe Becher <[EMAIL PROTECTED]> wrote: > You would need a wrapper to retrieve all logical drives using > win32api.GetLogicalDriveStrings(),check the drive type with > win32file.GetDriveType() and then os.walk() those local fixed drives. http://groups-beta.google.

Re: os.walk(entire filesystem)

2005-03-10 Thread Uwe Becher
rbt wrote: More of an OS question than a Python question, but it is Python related so here goes: When I do os.walk('/') on a Linux computer, the entire file system is walked. On windows, however, I can only walk one drive at a time (C:\, D:\, etc.). Is there a way to make os.walk() behave on Wi

Re: os.walk(entire filesystem)

2005-03-09 Thread Grumman
Tobiah wrote: When I do os.walk('/') on a Linux computer, the entire file system is walked. On windows, however, I can only walk one drive at a time (C:\, D:\, etc.). If this is a personal utility for one computer, and if you run XP on that computer, then you have the ability to mount secondar

Re: os.walk(entire filesystem)

2005-03-09 Thread Larry Bates
I don't think what you want would even work. You can't walk A: unless a floppy is present, O/S will bark at you. You can't walk D: (cdrom drive) unless a CDROM is present. What about network drives??? Unlike Linux where these directories appear to be empty if nothing is mounted Windows tries to

Re: os.walk(entire filesystem)

2005-03-09 Thread Tobiah
When I do os.walk('/') on a Linux computer, the entire file system is walked. On windows, however, I can only walk one drive at a time (C:\, D:\, etc.). If this is a personal utility for one computer, and if you run XP on that computer, then you have the ability to mount secondary drives on to

Re: os.walk(entire filesystem)

2005-03-09 Thread Peter Hansen
rbt wrote: More of an OS question than a Python question, but it is Python related so here goes: When I do os.walk('/') on a Linux computer, the entire file system is walked. On windows, however, I can only walk one drive at a time (C:\, D:\, etc.). Is there a way to make os.walk() behave on Wi

Re: os.walk()

2005-02-17 Thread Mike Meyer
rbt <[EMAIL PROTECTED]> writes: > Could someone demonstrate the correct/proper way to use os.walk() to > skip certain files and folders while walking a specified path? I've > read the module docs and googled to no avail and posted here about > other os.walk issues, but I think I need to back up to

Re: os.walk()

2005-02-17 Thread Max Erickson
os.walk() is a generator. When you iterate over it, like in a for loop, as for r,ds,fs in os.walk(...): r, ds and fs are set to new values at the beginning of each iteration. If you want to end up with a list of files or dirs, rather than processing them in the bodies of the file and dir for loop

Re: os.walk()

2005-02-17 Thread rbt
Roel Schroeven wrote: rbt wrote: The problem I run into is that some of the files and dirs are not removed while others are. I can be more specific and give exact examples if needed. On WinXP, 'pagefile.sys' is always removed, while 'UsrClass.dat' is *never* removed, etc. Keep in mind that the com

Re: os.walk()

2005-02-17 Thread Roel Schroeven
rbt wrote: > The problem I run into is that some of the files and dirs are not > removed while others are. I can be more specific and give exact examples > if needed. On WinXP, 'pagefile.sys' is always removed, while > 'UsrClass.dat' is *never* removed, etc. Keep in mind that the comparisons are d

Re: os.walk()

2005-02-17 Thread Dan Perl
"rbt" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Could someone demonstrate the correct/proper way to use os.walk() to skip > certain files and folders while walking a specified path? I've read the > module docs and googled to no avail and posted here about other os.walk > is

Re: os.walk() usage

2005-02-15 Thread rbt
[EMAIL PROTECTED] wrote: every object in os.walk() returns a 3-tuple, like below, it seems your code assumes it returns only a list of files. for d in os.walk('c:\\temp'): (dirpath, dirnames, filenames) = d print dirpath print dirnames print filenames Thank you, this

RE: os.walk() usage

2005-02-15 Thread Batista, Facundo
Title: RE: os.walk() usage [rbt] #- The problem I'm encountering is passing the list to other functions. #- It's almost as if each function needs to build the list #- itself (walk the #- filesystem)... which gets in the way of what I was asked to #- do (break #- this thi

Re: os.walk() usage

2005-02-15 Thread bruno modulix
rbt wrote: I'm trying to write very small, modular code as functions to break up a big monolithic script that does a file system search for particular strings. The script works well, but it's not easy to maintain or add features to. I'd like to have a function that builds a list of files with o

Re: os.walk() usage

2005-02-15 Thread [EMAIL PROTECTED]
every object in os.walk() returns a 3-tuple, like below, it seems your code assumes it returns only a list of files. for d in os.walk('c:\\temp'): (dirpath, dirnames, filenames) = d print dirpath print dirnames print filenames -- http://mail.python.org/mailman/lis

Re: os.walk bug?

2004-12-18 Thread Alex Martelli
Terry Reedy <[EMAIL PROTECTED]> wrote: > "Alex Martelli" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > for item in alist: > >if isnasty(item): > >alist.remove(item) > > > > changing the header to ``in alist[:]:'' or ``in list(alist):'' probably > > makes this code

Re: os.walk bug?

2004-12-18 Thread Terry Reedy
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > for item in alist: >if isnasty(item): >alist.remove(item) > > changing the header to ``in alist[:]:'' or ``in list(alist):'' probably > makes this code work, but it still can't make it GOOD... good would be:

Re: os.walk bug?

2004-12-18 Thread Alex Martelli
Adam DePrince <[EMAIL PROTECTED]> wrote: > Each iteration of os.walk returns three parameters; one of those, dirs, > is a list of directories within the current directory pointed at by > root. Yes, it does. > Am I correct to assume that you beleve that by changing the contents of > dir you will

Re: os.walk bug?

2004-12-16 Thread Tim Peters
[Adam DePrince] > Each iteration of os.walk returns three parameters; one of those, > dirs, is a list of directories within the current directory pointed at > by root. Right. > Am I correct to assume that you beleve that by changing the > contents of dir you will affect how os.walk traverses the

Re: os.walk bug?

2004-12-16 Thread Adam DePrince
On Thu, 2004-12-16 at 14:45, Gabriel Cosentino de Barros wrote: > Hi > > I'm new to the list. i found a bad behaviour of os.walk that i can > reproduce 100% but didn't find an answer to why it does that > > I have the folowing tree: > > t:\dir1 > t:\dir1\2000 > t:\dir1\2001 > t:\dir1\content >

Re: os.walk bug?

2004-12-16 Thread Tim Peters
[Gabriel Cosentino de Barros] ... > for root, dirs, files in os.walk('t:\'): > # -- do stuff > print "working on", root > # -- stuff done > > print 'DEBUG: dirs =', dirs > for d in dirs: > # -- remove archive >

Re: os.walk bug?

2004-12-16 Thread Terry Reedy
os.walk bug?--- for d in dirs: # -- remove archive if d[:2] == '20': print "--- removing:", d dirs.remove(d) -- Please post in plain text, not html/rtf. It is easier to reply to. Without looking at