Storing of folder structure in SQL DB
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu Apr 5 09:58:05 EDT 2007
In <mailman.6025.1175776544.32031.python-list at python.org>, Amit Khemka
wrote:
> On 4/5/07, Amit Khemka <khemkaamit at gmail.com> wrote:
>> On 5 Apr 2007 04:58:22 -0700, Sergei Minayev <sergei.minayev at gmail.com> wrote:
> <snip>
>> An Example:
>>
>> import os
>> root='/my/root/directory'
>> id =0
>> tree={root:(-1, id)}
>> id+=1
>> for path, dirs, files in os.walk(root):
>> for dir in dirs:
>> if not tree.has_key(path+'/'+dir):
>> tree[path+'/'+dir]=(tree[path][1], id)
>> id+=1
>>
>> […]
>
> use os.sep instead of '/' !
Or even better `os.path.join()` instead of building the strings with ``+``.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list