Re: [Tutor] scratching my head

2015-08-05 Thread Laura Creighton
In a message of Wed, 05 Aug 2015 08:43:45 +0200, Peter Otten writes: >Laura Creighton wrote: >but I don't think that's simpler. Can you enlighten me? When I got here, I landed in the middle of a discussion on how to use regexps for solving this. Plus a slew of string handling functions, none of w

Re: [Tutor] scratching my head - still

2015-08-05 Thread Peter Otten
Cameron Simpson wrote: > On 05Aug2015 12:46, Steven D'Aprano wrote: >>On Tue, Aug 04, 2015 at 05:52:15PM -0700, Clayton Kirkwood wrote: >>> As seen below (closely), some filenames are not being removed while >>> others are, such as in the first stanza, some pdfs are removed, some >>> aren't. In t

Re: [Tutor] scratching my head

2015-08-04 Thread Peter Otten
Laura Creighton wrote: > In a message of Mon, 03 Aug 2015 18:22:32 +1000, Cameron Simpson writes: > >>That depends. This is the tutor list; we're helping Clayton debug his code >>as an aid to learning. While it's good to know about the facilities in the >>standard library, pointing him directly a

Re: [Tutor] scratching my head - still

2015-08-04 Thread Cameron Simpson
On 05Aug2015 12:46, Steven D'Aprano wrote: On Tue, Aug 04, 2015 at 05:52:15PM -0700, Clayton Kirkwood wrote: As seen below (closely), some filenames are not being removed while others are, such as in the first stanza, some pdfs are removed, some aren't. In the second stanza, Thumbs.db makes it

Re: [Tutor] scratching my head - still

2015-08-04 Thread Steven D'Aprano
On Tue, Aug 04, 2015 at 05:52:15PM -0700, Clayton Kirkwood wrote: > As seen below (closely), some filenames are not being removed while others > are, such as in the first stanza, some pdfs are removed, some aren't. In the > second stanza, Thumbs.db makes it through, but was caught in the first > st

Re: [Tutor] scratching my head - still

2015-08-04 Thread Clayton Kirkwood
As seen below (closely), some filenames are not being removed while others are, such as in the first stanza, some pdfs are removed, some aren't. In the second stanza, Thumbs.db makes it through, but was caught in the first stanza. (Thanks for those who have proffered solutions to date!) I see no lo

Re: [Tutor] scratching my head

2015-08-04 Thread Emile van Sebille
On 8/3/2015 1:22 AM, Cameron Simpson wrote: That depends. This is the tutor list; we're helping Clayton debug his code as an aid to learning. While it's good to know about the facilities in the standard library, pointing him directly at fnmatch (which I'd entirely forgotten) is the "give a man a

Re: [Tutor] scratching my head

2015-08-03 Thread Laura Creighton
In a message of Mon, 03 Aug 2015 18:22:32 +1000, Cameron Simpson writes: >That depends. This is the tutor list; we're helping Clayton debug his code as >an aid to learning. While it's good to know about the facilities in the >standard library, pointing him directly at fnmatch (which I'd entirely

Re: [Tutor] scratching my head

2015-08-03 Thread Cameron Simpson
On 03Aug2015 08:12, Laura Creighton wrote: I think people are giving you sub-optimal advice. Python has a module in the standard library for doing exactly what you want to do -- match files with certain extensions. See: https://docs.python.org/2/library/fnmatch.html It's unix style file match

Re: [Tutor] scratching my head

2015-08-02 Thread Válas Péter
2015-08-02 23:44 GMT+02:00 Clayton Kirkwood : > > > for dir_path, directories, files in os.walk(main_dir): > for file in files: > #print( " file = ", file) > # if( ("(\.jpg|\.png|\.avi|\.mp4)$") not in file.lower() ): > > > I supppose you want to use regular expressions here and

Re: [Tutor] scratching my head

2015-08-02 Thread Laura Creighton
I think people are giving you sub-optimal advice. Python has a module in the standard library for doing exactly what you want to do -- match files with certain extensions. See: https://docs.python.org/2/library/fnmatch.html It's unix style file matching, but I am fairly certain this works on win

Re: [Tutor] scratching my head

2015-08-02 Thread Clayton Kirkwood
> -Original Message- > From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On > Behalf Of Steven D'Aprano > Sent: Sunday, August 02, 2015 5:49 PM > To: tutor@python.org > Subject: Re: [Tutor] scratching my head > > On Sun, Aug 02, 2015 at 02:44

Re: [Tutor] scratching my head

2015-08-02 Thread Clayton Kirkwood
> -Original Message- > From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On > Behalf Of Cameron Simpson > Sent: Sunday, August 02, 2015 6:03 PM > To: tutor@python.org > Subject: Re: [Tutor] scratching my head > > On 02Aug2015 16:15, Clayton Kirkwoo

Re: [Tutor] scratching my head

2015-08-02 Thread Cameron Simpson
On 02Aug2015 16:15, Clayton Kirkwood wrote: Behalf Of Cameron Simpson Sent: Sunday, August 02, 2015 3:35 PM [...] Personally I'd be reaching for os.path.splitext. Untested example below: from os.path import splitext for dir_path, directories, files in os.walk(main_dir): for fil

Re: [Tutor] scratching my head

2015-08-02 Thread Steven D'Aprano
On Sun, Aug 02, 2015 at 11:46:31PM +0100, Alan Gauld wrote: > On 02/08/15 23:01, Alan Gauld wrote: > > >found = False > >for s in (".jpg",".png",".avi",".mp4"): > > found = test or (s in file.lower()) > > Oops, that should be: > > found = found or (s in file.lower()) extensions = (".jpg",".

Re: [Tutor] scratching my head

2015-08-02 Thread Steven D'Aprano
On Sun, Aug 02, 2015 at 02:44:15PM -0700, Clayton Kirkwood wrote: > for dir_path, directories, files in os.walk(main_dir): > for file in files: > #print( " file = ", file) > # if( ("(\.jpg|\.png|\.avi|\.mp4)$") not in file.lower() ): > #if( (".jpg" or ".png" or ".avi" or

Re: [Tutor] scratching my head

2015-08-02 Thread Clayton Kirkwood
> -Original Message- > From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On > Behalf Of Cameron Simpson > Sent: Sunday, August 02, 2015 3:35 PM > To: tutor@python.org > Subject: Re: [Tutor] scratching my head > > On 02Aug2015 23:01, ALAN GAULD wro

Re: [Tutor] scratching my head

2015-08-02 Thread Alan Gauld
On 02/08/15 23:01, Alan Gauld wrote: found = False for s in (".jpg",".png",".avi",".mp4"): found = test or (s in file.lower()) Oops, that should be: found = found or (s in file.lower()) Sorry, 'test' was my first choice of name but I changed it to found later. But not everywhere :-(

Re: [Tutor] scratching my head

2015-08-02 Thread Cameron Simpson
On 02Aug2015 23:01, ALAN GAULD wrote: On 02/08/15 22:44, Clayton Kirkwood wrote: for dir_path, directories, files in os.walk(main_dir): for file in files: #print( " file = ", file) # if( ("(\.jpg|\.png|\.avi|\.mp4)$") not in file.lower() ): Python sees that as a single strin

Re: [Tutor] scratching my head

2015-08-02 Thread Clayton Kirkwood
> -Original Message- > From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On > Behalf Of Alan Gauld > Sent: Sunday, August 02, 2015 3:01 PM > To: tutor@python.org > Subject: Re: [Tutor] scratching my head > > On 02/08/15 22:44, Clayton Kirkwood wr

Re: [Tutor] scratching my head

2015-08-02 Thread Alan Gauld
On 02/08/15 22:44, Clayton Kirkwood wrote: for dir_path, directories, files in os.walk(main_dir): for file in files: #print( " file = ", file) # if( ("(\.jpg|\.png|\.avi|\.mp4)$") not in file.lower() ): Python sees that as a single string. That string is not in your filename

[Tutor] scratching my head

2015-08-02 Thread Clayton Kirkwood
Hey, been awhile, but I ran into os.walk and it fit what I needed to do for an issue I've had for a long time: I have tons of pictures in my top directory of pictures which are duplicated into properly named subdirectories. Please see issues above my questions with large gaps below. TIA, Clayton