I made a script in the past to mass rename any file greater than x characters in a directory. When I made that script I had a source directory which you would need to input manually. Any file that was over x characters in that directory would be stripped of it's extension, renamed, then the extension would be re added and it would use os.path.join to join the source and the newly created filename+ext. I'm now making another script and used os.path.join("Folder in the current dir", "file in that dir"). Because this worked I'm guessing that when os.path.join is called with just a foldername and no full path in it's first parameter it starts it's search from the directory that the script it was run in? Just wondering if this is correct.
Asked
Active
Viewed 715 times
-1
-
1Whatever you pass is going to be joined whether it exists or not, why would you think join searched anywhere? `print(os.path.join("!&£%","!&£%")) -> !&£%/!&£%` – Padraic Cunningham Sep 15 '15 at 21:21
-
The answer to your implied question is that you've joined together a "relative path", which when used with a filesystem function (like open) will be relative to the Current Working Directory of your script, which is usually the current directory of the shell that you started it from. – Max Sep 15 '15 at 21:37
2 Answers
1
os.path.join
has nothing to do with any actual filesystem, and does not "start" anywhere. It simply joins two arbitrary paths, whether they exist or not.

Daniel Roseman
- 588,541
- 66
- 880
- 895
0
What os.path.join
does is to just join path elements the system-compatible way, taking into effect the particular directory separator character, etc., into account. It's a simple string manipulation tool.
So the returned result simply starts from whatever you give to it as the first argument.

Cong Ma
- 10,692
- 3
- 31
- 47