path = r"C:\Users\mememe\Google Drive\Programs\Python\file.csv"

Closing the path in r"string" also solved this problem very well.

Answer from billmanH on Stack Overflow
🌐
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 # Alternative: Escape the backslashes path_with_spaces_escaped = "F:\\python\\New folder (2)" if os.path.isdir(path_with_spaces_escaped): print(f"'{path_with_spaces_escaped}' is a directory.") else: print(f"'{path_with_spaces_escaped}' is NOT a directory or does not exist.")
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
How can i handle filepath while has spaces followed with hyphen - Curriculum Help - The freeCodeCamp Forum
October 25, 2021 - Hi All, I need help to read the file path which is as below: file = os.listdir(“C:/Users/username/OneDrive - Company Name/Documents/Project Name/projectid/projectfolder/”) In the above example when i try to access this path, i am getting exception as below : [WinError 3] The system cannot ...
🌐
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

🌐
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
🌐
Python Forum
python-forum.io › thread-10689.html
dealing with spaces in file names
June 1, 2018 - example import os file = "C:\\test file.txt" os.system("start '" +file +"'")Error:The system cannot find the file 'C:\test.im just looking to open any file with windows default applications
Find elsewhere
🌐
Reddit
reddit.com › r/learnprogramming › how do i get python to open a file but the filename has spaces in it?
r/learnprogramming on Reddit: How do I get python to open a file but the filename has spaces in it?
June 4, 2018 -

I'm trying to write some code to open a file with its default program, but it can't be opened because the filename has spaces in it.

import subprocess
subprocess.Popen(['start', 'C:\\Folder\\This File'], shell=True)

Running this just opens the command prompt for some reason. It opens the file just fine if I remove the spaces, but I want to leave the spaces in the filename. I've googling solutions but none are for this function I'm trying to use. How do I go about this?

🌐
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.
🌐
Quora
quora.com › Is-it-okay-to-have-spaces-in-the-name-of-the-file-in-the-Python-file
Is it okay to have spaces in the name of the file in the Python file? - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
McNeel Forum
discourse.mcneel.com › scripting
RunPythonScript with spaces in file path - Scripting - McNeel Forum
March 17, 2025 - I’m trying to run Rhino + python script using Task Scheduler using the following syntax: “C:\Program Files\Rhino 8\System\Rhino.exe” /nosplash /runscript=“_-RunPythonScript ‘C:\Users\me\Company Name With Spaces\Folder Name With Spaces\PythonScript.py’” I put the file path in single ...
🌐
Stack Overflow
stackoverflow.com › questions › 38697330 › windows-path-with-spaces-in-python
Windows path with spaces in python - Stack Overflow
from pymatbridge import Matlab lab = Matlab(executable=r'"c:\Program Files \MATLAB\bin\matlab.exe"') lab.start() This works fine as I am using the raw string formatting to the hard-coded string. Now, the issue is that the string is passed as a variable. So, imagine I have a variable like: ... Now, I am unable to figure out how to get the equivalent raw string from this. I tried may things like shlex.quote(path) and this makes issue with the \b. Without conversion to the raw string, the space in Program Files causes a problem, I think.
🌐
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 ...
🌐
Python
docs.python.org › 3 › library › os.path.html
os.path — Common pathname manipulations
Return True if path is a reserved pathname on the current system. On Windows, reserved filenames include those that end with a space or dot; those that contain colons (i.e. file streams such as “name:stream”), wildcard characters (i.e.
🌐
Directory Opus
resource.dopus.com › help & support
Trouble passing directory with spaces to python script - Help & Support - Directory Opus Resource Centre
April 2, 2023 - I just have a button that calls ... files in os.walk(sys.argv[1]):. Issue is, if the current directory has a space in the name, like \New folder, the python script errors out....
🌐
sqlpey
sqlpey.com › python › how-to-handle-whitespaces-in-windows-file-paths-with-python
How to Handle Whitespaces in Windows File Paths with Python …
November 24, 2024 - Despite the file being present, Python struggles in this scenario mainly due to the space in the folder name “SEM 2”. So, how can we navigate around this issue? One straightforward solution is to utilize Python’s raw string notation. By prefixing the string with r, Python treats the backslashes as literal characters and does not interpret them as escape characters. ... By doing this, you can ensure that the file path is recognized properly, allowing you to perform file operations without running into issues due to whitespace.
🌐
Eli Bendersky
eli.thegreenplace.net › 2011 › 01 › 28 › on-spaces-in-the-paths-of-programs-and-files-on-windows
On spaces in the paths of programs and files on Windows - Eli Bendersky's website
January 28, 2011 - For the sake of example let's take a trivial batch script called dumpfile.bat: ... All it does is print the contents of the file passed to it as the first argument. I will place it in D:\temp\Spaces dir. How do I invoke this script with system? By quoting around the executable name: import ...