Skip to main content
added 16 characters in body
Source Link
Barmar
  • 769.5k
  • 54
  • 527
  • 641

I'm looking to rename one of my files using os.rename, the code is a little bit messy but currently it gives me a result that looks like it should work, but I end up getting an error. (path is removed but it is not actually removed in the code)

Snippet of my code:

mxk='''"'''
root = Tk()
root.withdraw()
m = root.clipboard_get() #all clipboard functions working 
bb=r"\blank.pdf"
cc=mxk
nd = (m[:40]+bb+cc)
print(m,nd)
os.rename(m, nd)

Print response: (m, nd) "C:\l-final_words.pdf" "C:\blank.pdf"

"C:\l-final_words.pdf" "C:\blank.pdf"

Error:

 File "C:\main.py", line 179, in <module>
    os.rename(m, nd)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:\\l-final_words.pdf"' -> '"C:\\Ublank.pdf"'
 File "C:\main.py", line 179, in <module>
    os.rename(m, nd)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:\\l-final_words.pdf"' -> '"C:\\Ublank.pdf"'

Does anybody have any suggestions fixing this code?

I'm looking to rename one of my files using os.rename, the code is a little bit messy but currently it gives me a result that looks like it should work, but I end up getting an error. (path is removed but it is not actually removed in the code)

Snippet of my code:

mxk='''"'''
root = Tk()
root.withdraw()
m = root.clipboard_get() #all clipboard functions working 
bb=r"\blank.pdf"
cc=mxk
nd = (m[:40]+bb+cc)
print(m,nd)
os.rename(m, nd)

Print response: (m, nd) "C:\l-final_words.pdf" "C:\blank.pdf"

Error:

 File "C:\main.py", line 179, in <module>
    os.rename(m, nd)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:\\l-final_words.pdf"' -> '"C:\\Ublank.pdf"'

Does anybody have any suggestions fixing this code?

I'm looking to rename one of my files using os.rename, the code is a little bit messy but currently it gives me a result that looks like it should work, but I end up getting an error. (path is removed but it is not actually removed in the code)

Snippet of my code:

mxk='''"'''
root = Tk()
root.withdraw()
m = root.clipboard_get() #all clipboard functions working 
bb=r"\blank.pdf"
cc=mxk
nd = (m[:40]+bb+cc)
print(m,nd)
os.rename(m, nd)

Print response: (m, nd)

"C:\l-final_words.pdf" "C:\blank.pdf"

Error:

 File "C:\main.py", line 179, in <module>
    os.rename(m, nd)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:\\l-final_words.pdf"' -> '"C:\\Ublank.pdf"'

Does anybody have any suggestions fixing this code?

Source Link

Problems with os.rename | OSError: [WinError 123]

I'm looking to rename one of my files using os.rename, the code is a little bit messy but currently it gives me a result that looks like it should work, but I end up getting an error. (path is removed but it is not actually removed in the code)

Snippet of my code:

mxk='''"'''
root = Tk()
root.withdraw()
m = root.clipboard_get() #all clipboard functions working 
bb=r"\blank.pdf"
cc=mxk
nd = (m[:40]+bb+cc)
print(m,nd)
os.rename(m, nd)

Print response: (m, nd) "C:\l-final_words.pdf" "C:\blank.pdf"

Error:

 File "C:\main.py", line 179, in <module>
    os.rename(m, nd)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:\\l-final_words.pdf"' -> '"C:\\Ublank.pdf"'

Does anybody have any suggestions fixing this code?