Parsing problems: A journey from a text file to a directory tree

Larry Bates larry.bates at websafe.com
Mon Sep 17 11:06:12 EDT 2007


Since you are going to need to do a dialog, I would use wxWindows tree
control.  It already knows how to do what you describe.  Then you can
just walk all the branches and create the folders.

-Larry

Martin M. wrote:
> Hi everybody,
> 
> Some of my colleagues want me to write a script for easy folder and
> subfolder creation on the Mac.
> 
> The script is supposed to scan a text file containing directory trees
> in the following format:
> 
> [New client]
> |-Invoices
> |-Offers
> |--Denied
> |--Accepted
> |-Delivery notes
> 
> As you can see, the folder hierarchy is expressed by the amounts of
> minuses, each section header framed by brackets (like in Windows
> config files).
> 
> After the scan process, the script is supposed to show a dialog, where
> the user can choose from the different sections (e.g. 'Alphabet',
> 'Months', 'New client' etc.). Then the script will create the
> corresponding folder hierarchy in the currently selected folder (done
> via AppleScript).
> 
> But currently I simply don't know how to parse these folder lists and
> how to save them in an array accordingly.
> 
> First I thought of an array like this:
> 
> dirtreedb = {'New client': {'Invoices': {}, 'Offers': {'Denied': {},
> 'Accpeted': {}}, 'Delivery notes': {}}}
> 
> But this doesn't do the trick, as I also have to save the hierarchy
> level of the current folder as well...
> 
> Argh, I really don't get my head around this problem and I need your
> help. I have the feeling, that the answer is not that complicated, but
> I just don't get it right now...
> 
> Your desperate,
> 
> Martin
> 



More information about the Python-list mailing list