Newbie-ish question

Pete Shinners pete at shinners.org
Mon Nov 19 19:32:17 EST 2001


Patrick Moorman wrote:

> I have a directory containing a large number of files in the format xy.txt
> where x is a string of numbers and/or letters and y is a sequential number
> with either 2 or 3 digits.  Example:  1foo23012.txt or foo12305.txt.  How
> would I go about identifying all of the files in a sequence and moving them
> to their own sub-directory.  I am slowly picking up on Python, but there is
> a long ways to go.  Thanks for any help.


you've got one problem with your situation. if the first part of the 
filename includes letters and numbers, and the second numeric part is 2 
_OR_ 3 numbers, how do you know where the name part ends and the number 
part starts??

is "1foo23012.txt" become "lfoo230, 12" or is it "lfoo23, 012" ??


you should start with the os.path functions to help you manage 
filenames. you can use string functions to determine if characters are 
letters or digits.







More information about the Python-list mailing list