views:

1046

answers:

3
+1  A: 

to join a windows path, try

mypath=os.path.join('c:\\', 'sourcedir')

basically, you will need to escape the slash

ghostdog74
+4  A: 

The reason os.path.join('C:', 'src') is not working as you expect is because of something in the documentation that you linked to:

Note that on Windows, since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative to the current directory on drive C: (c:foo), not c:\foo.

As ghostdog said, you probably want mypath=os.path.join('c:\\', 'sourcedir')

Smashery
+2  A: 

Windows has a concept of current directory for each drive. Because of that, "c:sourcedir" means "sourcedir" inside the current C: directory, and you'll need to specify an absolute directory.

Any of these should work and give the same result, but I don't have a Windows VM fired up at the moment to double check:

"c:/sourcedir"
os.path.join("/", "c:", "sourcedir")
os.path.join("c:/", "sourcedir")
Roger Pate
os.path.join('C:/', 'sourcedir') worked as expected.I thank you very much good sir :)the others '//' 'c:''c:\\'did not work (C:\\ created two backslashes, C:\ didn't work at all)Thanks again ghostdog74, Smashery, and Roger Pate. I am in your debt :)
Frank E.
Sorry, line breaks weren't kept in comment, it looks very messy
Frank E.