[Tutor] annoying directory structure

Zachary Ware zachary.ware+pytut at gmail.com
Fri Apr 10 01:31:49 CEST 2015


(Please use a bottom-posting/interleaved style of reply on this list,
it makes conversations much easier to follow.  I've fixed your message
in my response below.)

On Thu, Apr 9, 2015 at 5:17 PM, Jim Mooney <cybervigilante at gmail.com> wrote:
>> > Another question. I have a set of training vids. Unfortunately, each vid
>> is
>> > in a subdir inside a subdir inside a subdir inside a subdir inside the
>> > directory. Going down, down, down, up, up, up to nab them (they're short)
>> > and remember where I am, is annoying. How do I use python to get a simple
>> > straight list of the vids in directory order - full windows path - so I
>> can
>> > just copy and plug the paths into windows explorer, one at a time?
>>
>> Have a look at os.walk(), it will enable you to walk (hence the name)
>> through all directories in a tree.  Take a crack at it, and if you
>> have trouble come back with some code for us to look at.  You may also
>> need os.path.abspath to get the full path.
>
> Looks like I can work it, but some walk paths are coming out as two strings
> back to back, which I know python concatenates with print, but how do I
> concatenate them without print so I can use them in my script to append to
> the mp4 filenames and have a windows readable path?. i.e., I am getting
> this sort of triplet when I go through the generator. After doing that the
> rest seems easy enough:
>
> A = ('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'])
>
>>> A[0]
>
> ('I:\\VIDS\\Learn Python Track\\07. Regular Expressions in Python\\Stage '
>  '1\\01. Introduction to Regular Expressions\\07. Compiling and Loops')
>
> Still two unconcatenated strings
>
> And why do I still have tuple parentheses for A[0], which should be a
> concatenated string?

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


More information about the Tutor mailing list