[Tutor] Tutor Digest, Vol 134, Issue 27 - Re: annoying directory structure (Zachary Ware)

Jim Mooney cybervigilante at gmail.com
Fri Apr 10 05:07:33 CEST 2015


>
> I'll need to see some actual code (namely, where and how you used
> os.walk) to have any real idea of what's going on. The online docs for
> os.walk have a pretty good explanation and example.


Zach

This worked. I didn't know why I got doubled strings, but print
concatenated them so I printed to a file, and the text lines all open an
mp4 in windows explorer, as expected. Unfortunately they aren't in order,
so I guess I'll have to actually read up on walk. I just wanted to knock it
out quickly by figuring out the walk output format, and get on with the
course ;')

tutfiles = open('tutfiles.txt', 'w')
p = os.walk('I:\\VIDS\\Learn Python Track\\')
for triplet in p:
    if triplet[2] == []:
        continue
    else:
        if 'mp4' in triplet[2][0]:
            print(triplet[0] + '\\' + triplet[2][0], file=tutfiles)

tutfiles.close()

Here are the out of order textlines, going from Track\08 to Track\01

I:\VIDS\Learn Python Track\08. Using Databases in Python\Stage 1\01. Meet
Peewee\01. Meet Peewee, Our ORM\Meet Peewee, Our ORM.mp4
I:\VIDS\Learn Python Track\01. Python Basics\Python Basics\Stage 6\06.
Pick a Number! Any Number!\02. The Solution\The Solution.mp4

Here is what I meant by doubled strings. The tuples output by walk had two
strings in a row as element zero, Prior to the first comma, with element 1
being an empty list, so I couldn't figure how to concatenate the two
strings directly, without print, to use in my file listing.

(*'I:\\VIDS\\Learn Python Track\\07. Regular Expressions in Python\\Stage '
'1\\01. Introduction to Regular Expressions\\07. Compiling and Loops'*, [],
['Compiling and Loops.mp4', 'Compiling and Loops.srt'])

Jim


More information about the Tutor mailing list