files,folders,paths

Ben Finney ben+python at benfinney.id.au
Mon Feb 14 00:39:43 CET 2011


ecu_jon <hayesjdno3 at yahoo.com> writes:

> can you give an example of how to build a folder name, maybe as a
> string, with parts of it as variables, that have to be strung
> together. like x = "//servername/+variable+"/"+variable+"/"

    import os.path

    infile_path = os.path.join(["//servername", start_dir, other_dir])

Read the documentation for ‘os.path.join’. It's fundamental if you're
working with filesystem paths.

> when i did something liek that the end result string was like
> //servername/folder/folder\file and i got an error

That path should work on MS Windows. If you want us to comment on the
error, you'll need to show the code here *and* the error traceback.

-- 
 \        “If this is your first visit to the USSR, you are welcome to |
  `\                                          it.” —hotel room, Moscow |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list