python - os.remove can't find file because of slashes -


i want remove file. file created earlier same program want delete it.

this have:

user_file_name = 'user_info.json' file_to_delete = os.path.join(addon_data['profile_dir'], user_file_name) xbmc.log('file delete:') print(file_to_delete) os.remove(file_to_delete) 

this (usernames , likes redacted due paranoid tendencies):

notice: file delete: notice: c:\users\username\appdata\roaming\xbmc\userdata\addon_data\script.name\user_info.json notice: [errno 2] no such file or directory: u'c:\\users\\username\\appdata\\roaming\\xbmc\\userdata\\addon_data\\script.name\\user_info.json' 

i think because of damn slashes. tried sorts of things, nothing seems work. no matter did string in file_to_delete, including not limited replacing backslashes forward slashes, file tried find , delete same in error line.

can me?

update:

so tried something. added os.remove(repr(file_to_delete)) after original os.remove(file_to_delete), have this:

if os.path.exists(file_to_delete):     xbmc.log('user file exists, prepairing delete')     xbmc.log('stats: %s' % os.access(file_to_delete, os.f_ok))     xbmc.log('stats: %s' % os.access(file_to_delete, os.w_ok))     xbmc.log('stats: %s' % os.access(file_to_delete, os.x_ok))     os.remove(file_to_delete)     os.remove(repr(file_to_delete)) 

if comment out os.remove(repr(file_to_delete)), same error before. if don't comment 1 one above it, error:

user file exists, prepairing delete stats: true previous line repeats 2 times. error: exception thrown (pythontocppexception) : -->python callback/script returned following error<-- . . . os.remove(repr(file_to_delete))     windowserror: [error 123] filename, directory name, or volume label syntax incorrect: "u'c:\\\\users\\\\username\\\\appdata\\\\roaming\\\\xbmc\\\\userdata\\\\addon_data\\\\script.name\\\\user_info.json'" 

if don't comment either 1 , run in is, same error above file is removed. ideas why happening?

update 2:

the behavior above happens in instance:

os.remove(file_to_delete) os.remove(file_to_delete) 

file removed, error:

windowserror: [error 2] system cannot find file specified: u'c:\\users\\username\\appdata\\roaming\\xbmc\\userdata\\addon_data\\script.name\\user_info.json' 

when use os.remove() different file in same folder, both built os.path.join(), once enough.

any ideas?

the file name string appear encoded unicode string.

perhaps try this:

file_to_delete= unicodedata.normalize('nfkd', file_to_delete).encode('ascii','ignore') os.remove(file_to_delete) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -