1

I'm working an OS X platform with Python 3 and I'm not quite sure how to create file paths that link into directories. I know that on the Windows platform it would look something like

import os
path = 'C:\\Users\\User\\Desktop\\<directory name>'
os.mkdir(path)
file = open(path + '\\<file name>.txt', w)
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Jason
  • 33
  • 1
  • 3
  • 13
  • Possible duplicate of [Finding a file's directory address on a Mac](http://stackoverflow.com/questions/3324486/finding-a-files-directory-address-on-a-mac) – OzizLK Jan 28 '17 at 03:27
  • It's close, but I'm creating the directory. Does `os.mkdir()` work the same in OSX as in windows? If – Jason Jan 28 '17 at 03:56
  • This one should help: [http://stackoverflow.com/questions/273192/how-to-check-if-a-directory-exists-and-create-it-if-necessary](http://stackoverflow.com/questions/273192/how-to-check-if-a-directory-exists-and-create-it-if-necessary) using os.makedirs. – Jorge Plaza Jan 28 '17 at 04:02

1 Answers1

1

Paths on OSX use the forward slash (which you can also use on windows). Other than that, the only difference is that OSX (and most other non-windows OS's) don't have drive letters.

The root of any OSX system is "/", everything else is below that. So, for example, your home directory is likely "/Users/myusername". OSX paths are case-insensitive, but case-preserving. That means that "/users/myusername" and "/Users/myusername" go to the same place. If the directory is created with capital letters, the capital letters is what will show with ls, in the finder, etc.

os.mkdir works the same way on all platforms, assuming you give a valid path.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685