xbmcvfs.delete() can't find file to delete
#1
I tried calling xbmcvfs.delete with the path to the file and with a file object but neither works. It worked in Frodo, but no go in Gotham.

Also, the Frodo python docs have a description for this:
http://mirrors.xbmc.org/docs/python-docs...ml#-delete

But the Gotham python docs are missing it:
http://mirrors.xbmc.org/docs/python-docs...ml#-delete

Are there any suggestions as to how to delete a file in Gotham?
Reply
#2
A debug log would be helpful. I use xbmcvfs.delete() in Artist Slideshow, and it's working fine in Gotham.
Reply
#3
The code:

Code:
xbmc.log('User File: %s' % user_file)
xbmcvfs.delete(user_file)

The log:
Code:
NOTICE: User File: C:\Users\---\AppData\Roaming\XBMC\userdata\addon_data\---\user_info.json
NOTICE: [Errno 2] No such file or directory: u'C:\\Users\\---\\AppData\\Roaming\\XBMC\\userdata\\addon_data\\---\\user_info.json'

It worked in Frodo. Updated to Gotham, and it stopped working.
Reply
#4
looks already wrong from the log message. no way that's gonna work like that
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#5
What seems wrong? The dashes are not part of the original log, I placed them in the post (I'm a wee bit paranoid).

I don't think the double slash are the cause since it is just a representation of a slash.

Edit: Also, I know for a fact that the file exists. When I copy the file path that is reported as non existent and paste it in a run window, it opens the correct file.
Reply
#6
Can anyone enlighten me as to what I'm doing wrong?
Reply
#7
I believe you need to get rid of the double backslashes and change them to single backslash... You Might try changing them to forward slashes(single)
Reply
#8
If you built the path by joining strings, that might be the problem. You might try using os.path.join. It would be really helpful to see more than two lines of code out of context and a little snippet of the log.
Reply
#9
A little more detailed code:

Code:
ADDON_DATA['addon'] = xbmcaddon.Addon()
ADDON_DATA['profile_dir'] = xbmc.translatePath(ADDON_DATA['addon'].getAddonInfo('profile')).decode('utf-8')
USER_FILE_NAME = 'user_info.json'
user_file = os.path.join(ADDON_DATA['profile_dir'], USER_FILE_NAME)
xbmc.log('User File: %s' % user_file)
xbmcvfs.delete(user_file)

results in (replaced actual username and addon name because of my paranoid nature):

Code:
11:18:09 T:1764  NOTICE: User File: C:\Users\USERNAME\AppData\Roaming\XBMC\userdata\addon_data\ADDON NAME\user_info.json
11:18:09 T:1764  NOTICE: [Errno 2] No such file or directory: u'C:\\Users\\USERNAME\\AppData\\Roaming\\XBMC\\userdata\\addon_data\\ADDON NAME\\user_info.json'
Reply
#10
Something odd. If I have this:
Code:
os.remove(user_file)

Nothing happens to the file and I get this (a xbmc notice):
Code:
NOTICE: [Errno 2] No such file or directory: u'C:\\Users\\USERNAME\\AppData\\Roaming\\XBMC\\userdata\\addon_data\\ADDON NAME\\user_info.json'

But if I have this:
Code:
os.remove(user_file)
os.remove(user_file)

The file is deleted and I get this (a python error):
Code:
WindowsError: [Error 2] The system cannot find the file specified: u'C:\\Users\\USERNAME\\AppData\\Roaming\\XBMC\\userdata\\addon_data\\ADDON NAME\\user_info.json'

Any ideas?
Reply
#11
I'm no python expert, I'll be the first to admit, but the only line that stands out to me is

(2014-06-03, 10:24)yosubis Wrote: user_file = os.path.join(ADDON_DATA['profile_dir'], USER_FILE_NAME)

As someone quite happy to admit they don't get the whole encode/decode utf-8 thing, even after reading lots of docs, I thought that would have to be:

Code:
user_file = os.path.join(ADDON_DATA['profile_dir'].encode('utf-8'), USER_FILE_NAME).decode('utf-8')

I'm going to assume that won't help, though, so will simply say - the error is quite clear: the file isn't found. That basically leaves you with two possibilities: either the file isn't where you think it is, or the path you're passing to xbmcvfs.delete isn't correct.
Reply
#12
But that's the thing, the file does exist and python even knows it's there. It just won't delete that file. It will delete other files in the same folder, joined in the same way, but not these one.

I tried this;
Code:
file_to_delete = os.path.join(ADDON_DATA['profile_dir'].encode('utf-8'), USER_FILE_NAME).decode('utf-8')
if os.path.exists(file_to_delete):
    xbmc.log('User file exists, Prepairing to 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)

And the log shows this:
Code:
10:55:26 T:6456  NOTICE: User file exists, Prepairing to delete
10:55:26 T:6456  NOTICE: stats F_OK: True
10:55:26 T:6456  NOTICE: stats W_OK: True
10:55:26 T:6456  NOTICE: stats R_OK: True
10:55:26 T:6456  NOTICE: [Errno 2] No such file or directory: u'C:\\Users\\USERNAME\\AppData\\Roaming\\XBMC\\userdata\\addon_data\\script.NAME\\user_info.json'

So the file is there. Python can find it except when trying to delete it. I have no idea why.
Reply
#13
Ok, it seems I found the problem. I put "time.sleep(2)" after "os.remove(file_to_delete)" and then everything worked.
Reply

Logout Mark Read Team Forum Stats Members Help
xbmcvfs.delete() can't find file to delete0