Skip to content


Subversion checkout URL

You can clone with
Download ZIP


xbmcvfs addition #71

1 commit merged into from

4 participants


here is a simple addition to xbmcvfs python module, checks for file or folder existence. needed on external python builds and smb://, among others


same comment as last time - we should mimic stdio. however, we can change that later so no objections on this going in for now.

@lucianm lucianm referenced this pull request from a commit
@opdenkamp opdenkamp Merged pull request #71 from pipelka/pvr-recordingslist-fix.
pvr: fix recordings list. display recordings if there are subdirectories

Hmm it return just "1". Should be true? Also one question: Why return string? I guess better return "True" for python.

Are you sure that this line returns "1"? Because the code says if the parameter passed to vfs_exists() is not a valid python string/unicode object it will return NULL which will probably end in an exception being thrown.

Yea I test it one of my add-on like this: print 'exsist: %s' % xbmcvfs.exists(xbmc.translatePath(cachedir))
and it print to log this: NOTICE: exsist: 1

Maybe I am on wrong line but something return "1".


Same here, maybe you can consider return "False" instead string "false"

This line doesn't return anything either. It just stores the result of the actual Exists() call in bResult. The generation of the actual python object that will be returned happens on line 203 (4 lines further down).

Sorry I don't know actually. But you get the point right?

line 202 returns bool bResult to the addon(True/False) and is constructed as bool

According to the Python API for Py_BuildValue (see the "b" in Py_BuildValue actually does not result in a boolean (True/False) but in an integer (from a character). Doesn't look like Py_BuildValue() has a way of returning the python objects True or False. That would have to be done using something like

if (bResult)

ok, fair ...

if xbmcvfs.exists(xbmc.translatePath(cachedir)):
    print "exists"
    print "doesnt exist"

would still work

How is that possible?

print xbmcvfs.exists(xbmc.translatePath(cachedir)) return integer (1/0) not a boolean (True/False)

I use it that way and it works

if xbmcvfs.exists(path):
do something


it works, try it ...

Confirmed. You are right it's working. Sorry for disturbed you guys.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 16, 2011
  1. @amet

    added: xbmcvfs.exists(path), check for a file or folder existence, mi…

    amet authored
    …mics Pythons os.path.exists()
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 0 deletions.
  1. +31 −0 xbmc/interfaces/python/xbmcmodule/xbmcvfsmodule.cpp
31 xbmc/interfaces/python/xbmcmodule/xbmcvfsmodule.cpp
@@ -170,13 +170,44 @@ extern "C" {
return Py_BuildValue((char*)"b", bResult);
+ PyDoc_STRVAR(exists__doc__,
+ "exists(path)\n"
+ "\n"
+ "path : file or folder"
+ "\n"
+ "example:\n"
+ " success = xbmcvfs.exists(path)\n");
+ // check for a file or folder existance, mimics Pythons os.path.exists()
+ PyObject* vfs_exists(File *self, PyObject *args, PyObject *kwds)
+ {
+ PyObject *f_line;
+ if (!PyArg_ParseTuple(
+ args,
+ (char*)"O",
+ &f_line))
+ {
+ return NULL;
+ }
+ CStdString strSource;
+ if (!PyXBMCGetUnicodeString(strSource, f_line, 1)) return NULL;
+ bool bResult;
+ CPyThreadState pyState;
+ bResult = self->pFile->Exists(strSource, false);
+ pyState.Restore();
+ return Py_BuildValue((char*)"b", bResult);
+ }
// define c functions to be used in python here
PyMethodDef xbmcvfsMethods[] = {
{(char*)"copy", (PyCFunction)vfs_copy, METH_VARARGS, copy__doc__},
{(char*)"delete", (PyCFunction)vfs_delete, METH_VARARGS, delete__doc__},
{(char*)"rename", (PyCFunction)vfs_rename, METH_VARARGS, rename__doc__},
+ {(char*)"exists", (PyCFunction)vfs_exists, METH_VARARGS, exists__doc__},
Something went wrong with that request. Please try again.