Not yet - I am seeing what appear to be inconsistencies in how this works on Mac but I have not yet determined if I am being a dummy or if this is really broken. @will10 - still poking, but on mac it may work better to use -ExportAll and not -SaveAs @will10 - I ended up quitting and rebooting an… Answer from pascal on discourse.mcneel.com
🌐
Python
docs.python.org › 3 › library › os.path.html
os.path — Common pathname manipulations
The return value is the concatenation of path and all members of *paths, with exactly one directory separator following each non-empty part, except the last. That is, the result will only end in a separator if the last part is either empty or ends in a separator. If a segment is an absolute path (which on Windows requires both a drive and a root), then all previous segments are ignored and joining continues from the absolute path segment. On Linux, for example: >>> os.path.join('/home/foo', 'bar') '/home/foo/bar' >>> os.path.join('/home/foo', '/home/bar') '/home/bar'
🌐
Reddit
reddit.com › r/learnpython › python cant open files with names in spaces
r/learnpython on Reddit: python cant open files with names in spaces
June 16, 2017 -

I'm creating a script that will read a bunch of .txt files from a directory. I am getting all the names of the files in the directory using

path = os.path.join(os.path.expanduser('~'), 'Desktop',)#Path to the folder here

for filename in os.listdir(path):
	path = path + '/' + filename

This is creating a new path for each file name, I am then looking to open each file within the for filename loop and extract data from it, however the filenames contain spaces so when i try to open the new path, i am getting a 'No such directory or file' error. I have also checked if the file exists using

print os.path.isdir(path)

and am being returned false for every one.

How can i solve this? thanks in advance

Note: It will take way to long to delete all the spaces from the filenames manually

🌐
GitHub
github.com › PyImageSearch › imutils › issues › 61
paths.py - replacing space with slash+space · Issue #61 · PyImageSearch/imutils
March 27, 2018 - First of all, thanks for the library. Very useful! Second, I wanted to ask you why do you replace space with slash+space in paths.py? Is this a bug or something you've done on purpose? imagePath = os.path.join(rootDir, filename).replace(" ", "\\ ") PS: I'm using Windows and Python3.
Author: PyImageSearch
🌐
Reddit
reddit.com › r/learnpython › how can i work around white space in a filepath?
r/learnpython on Reddit: How can I work around white space in a filepath?
December 19, 2022 -

I wrote a program that creates a directory/sub-directories in a specified location. I wrote it so that it allows for users to input what they want the directory to be named and then opens the newly created folder in file explorer, however, if a user chooses a file name that includes spaces I get an error.

import os

file = input(“Please enter file name: “)
user_id = os.getlogin()
filepath = f”C:/Users/{user_id}/Desktop”
path = os.path.join(filepath,file)

try:
    os.makedirs(path)
except FileExistsError:
    print(“This file name already exists”)

os.system(f”start C:/Users/{user_id}/Desktop/{file}”)

I tried using the replace method to insert escape characters and looked into pathlib but couldn’t figure out how to get around the spaces.

The error I get is a Windows error, not Python, but I’ve included it anyways (the file name I tried was TEST FOLDER).

Windows cannot find ‘C:/Users/12345/Desktop/TEST.’ Make sure you typed the name correctly, and then try again.
🌐
McNeel Forum
discourse.mcneel.com › scripting
Saving As with Spaces in the Path Name - Scripting - McNeel Forum
July 22, 2021 - To do this, I’ve done the following rhinoPath = os.path.join(basefilePath,rhinoFile) command = '-_SaveAs "{}"'.format(rhinoPath+'.3dm') print('RHINO PATH IS', command) rs.Command(command, True) The path name has spaces in it, and wherever ...
🌐
WMI
timgolden.me.uk › python › win32_how_do_i › run-a-command-with-a-space-in-it.html
Tim Golden's Python Stuff: Run a command with a space in it
import subprocess import os, sys import shutil import win32api # # Create a folder in the temp area with a space # in it; copy the notepad executable there and # create a text file which includes the location. # temp = os.environ['TEMP'] folder_name = os.path.join (temp, "abc def") os.mkdir (folder_name) doc_name = os.path.join (folder_name, "with-space.txt") executable_name = os.path.join (folder_name, "with-space.exe") open (doc_name, "w").write ("This is in %s" % doc_name) _, executable = win32api.FindExecutable (doc_name) # # The doubling up seems necessary on Win2K where the # first call doesn't return the full path name of, # say, notepad.exe.
🌐
Reddit
reddit.com › r/learnpython › handling file paths between os's
r/learnpython on Reddit: handling file paths between OS's
December 5, 2018 -

How do you guys deal with filenames with spaces in:

I have a file name:

/Users/me/Downloads/This is my file.xlsx

but it gets messed up as soon as it goes anywhere near a python script. The problem is, that in a company with 33,000 employees and me at the bottom of the ladder I can't expect others to just not put spaces in their filename.

I've tried using pathlib, but python seems to get in before hand so pathlib does this to the path:

from pathlib import Path

path = Path('/Users/me/Downloads/This\ is\ my\ file.xlsx')
path
/Users/me/Downloads/This\ is\ my\ file.xlsx

I've also tried:

path = (r'/Users/me/Downloads/This\ is\ my\ file.xlsx')

to no avail.

How can I get the correct filename no matter where it has come from (usually windows)

🌐
GitHub
bic-berkeley.github.io › psych-214-fall-2016 › path_manipulation.html
Making and breaking file paths in Python — Functional MRI methods
See: https://docs.python.org/3.5/library/os.path.html · os.path · dirname, basename, join, splitext, abspath · >>> import os.path · In IPython, you can tab complete on os.path to list the functions and attributes there. The first function we will use from os.path is dirname. To avoid typing os.path.dirname all the time, import the dirname function directly into the current name-space, by using the from module import ...
Find elsewhere
🌐
Codecademy
codecademy.com › docs › python › os module › .join()
Python | os Module | .join() | Codecademy
May 29, 2025 - It takes one or more path components as arguments and joins them together with the appropriate directory separator, which varies depending on the operating system (forward slash / for Unix-based systems and backslash \ for Windows). The method handles the complexities of path creation, such as dealing with absolute paths, redundant separators, and platform-specific considerations. This makes it essential for writing cross-platform Python applications that need to manipulate file paths in a reliable manner.
🌐
YouTube
youtube.com › codewrite
python path with spaces - YouTube
Download this code from https://codegive.com When working with file paths in Python, it's common to encounter paths that include spaces, especially on Window...
Published: December 26, 2023
Views: 20
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-os-path-join-method
Python | os.path.join() method - GeeksforGeeks
It represents the path components to be joined. A path-like object is either a string or bytes object representing a path. Note: The special syntax *args (here *paths) in function definitions in python is used to pass a variable number of arguments to a function. Return Type: This method returns a string which represents the concatenated path components. The os.path.join() method processes the path components and resolves them into a single, absolute path.
Published: July 11, 2025
🌐
Tutorialspoint
tutorialspoint.com › python › os_path_join.htm
Python os.path.join() Method
The Python os.path.join() method is used to construct a path by joining one or more path components. The method takes multiple path components (strings) and joins them together with appropriate directory separators (/ or \) depending on the
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › os.path.join.html
os.path.join() — Python Standard Library
Join two or more pathname components, inserting ‘/’ as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › python › python os.path.join() explained: syntax, examples and path handling guide
Python os.path.join() Explained: Syntax, Examples and Path Handling Guide | GoLinuxCloud
March 9, 2026 - The os.path.join() function always returns a string containing the combined path. The function returns a value of type str. ... The function automatically uses the correct separator based on the operating system. ... If extra separators are provided, Python automatically normalizes them. ... This ensures that paths remain clean and valid. Build a path with os.path.join(), then open the file for reading.
🌐
Code.mu
code.mu › en › python › manual › fs › os › path › join
The path.join method of the os module - joining paths in Python
The path.join method combines paths or their parts specified in the method parameter. The combination is performed using a separator specific to the used OS. For Windows, the separator \ is used, for Linux - /. If the last path component to be combined is empty, then the separator is placed ...
🌐
Python Academy
python-academy.org › function reference › os.path.join
os.path.join — Python Function Reference
A detailed reference of Python functions with examples. Find out how os.path.join works in Python. Join path parts with the separator of the current operating system.
🌐
McNeel Forum
discourse.mcneel.com › scripting
Batch processing files with a space in their path - Scripting - McNeel Forum
September 20, 2022 - I’m hoping to create a script that can search a folder for all files ending in .obj and apply ReduceMesh to them (I have a large number of files to do this to). So far my script is as so: import os import rhinoscriptsyntax as rs def getObjHelper(dir_path, matches): for root, dirnames, filenames in os.walk(dir_path): for file in filenames: if file.endswith('.obj'): matches.append(os.path.join(root, file)) for dir in dirnames: getObjHe...
🌐
DEV Community
dev.to › nazanin_ashrafi › windows-paths-with-spaces-in-pythons-os-2kl4
Windows paths with spaces in Python's `os` - DEV Community
December 22, 2025 - import os # Correct: Use 'r' before the string to create a raw string path_with_spaces = r"F:\python\New folder (2)" if os.path.isdir(path_with_spaces): print(f"'{path_with_spaces}' is a directory.") else: print(f"'{path_with_spaces}' is NOT a directory or does not exist.")
🌐
Reddit
reddit.com › r/learnpython › dealing with spaces when using file paths
r/learnpython on Reddit: Dealing with spaces when using file paths
December 27, 2021 -

Hey all - stupid question but how do I deal with spaces when I am using file paths?

I have a script I'm working on converting from Bash and one file that I need to past in from input is in the Application Support folder in my user directory -

So basically I have this
fileDir = input("Please pass the file directory here ")

fileDirReciever = fileDir+"/system_logs.logarchive.foo.txt

When I print FileDirReceiver it prints out :
Application\ Support/

But when I pass the variable into an open command

open (fileDirReciever ,"r")

FileNotFoundError: [Errno 2] No such file or directory:.../Application\\ Support/

I've tried using r to make it a literal with no luck as well. Thanks