Robert Fairbrother
Robert Fairbrother

Reputation: 31

Folder name with a \n

I have a default folder called \normal however python detects the \n same with if i put extracted \" I keep getting permission denied writing and assuming it is because of the missing \

\"folder_normal = "F:\Extractor\normal" folder_output = "F:\Extractor\Extracted\"

Edit

With the \ \ or the r it changes the folder to F:\\Extractor\\Extracted\\\\ what even with os.mkdir cannot find the folder

Upvotes: 2

Views: 639

Answers (3)

sniperd
sniperd

Reputation: 5274

When I write Python in windows and have to deal with paths, I simply use forward slashes instead of back slashes. Sure, you can do proper escaping but it always turns into a hassle of errors it seems. So, change all your

\

to

/

So in this case, write this:

folder_output = "F:/Extractor/Extracted/"

And you should be good to go!

Upvotes: 1

muminers
muminers

Reputation: 1210

use raw format

folder = r"F:\Extractor\normal"

It's the best way to write paths because you don't need to worry about possible changes where you will miss another \a \b \n \t \v sign.

Alternatively you can use "/" instead of "\".

See: https://community.esri.com/blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python to find other solutions

Upvotes: 2

Steven Black
Steven Black

Reputation: 2232

input an additional \

folder_normal = "F:\Extractor\\normal"
folder_output = "F:\Extractor\Extracted\"

Upvotes: 0

Related Questions