scan_directory() for python

This commit is contained in:
David Rose 2010-03-02 23:16:53 +00:00
parent 1a02e76c28
commit be494155cf
2 changed files with 30 additions and 0 deletions

View File

@ -1886,6 +1886,33 @@ scan_directory(vector_string &contents) const {
#endif #endif
} }
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: Filename::scan_directory
// Access: Published
// Description: This variant on scan_directory returns a Python list
// of strings on success, or None on failure.
////////////////////////////////////////////////////////////////////
PyObject *Filename::
scan_directory() const {
vector_string contents;
if (!scan_directory(contents)) {
PyObject *result = Py_None;
Py_INCREF(result);
return result;
}
PyObject *result = PyList_New(contents.size());
for (size_t i = 0; i < contents.size(); ++i) {
const string &filename = contents[i];
PyObject *str = PyString_FromStringAndSize(filename.data(), filename.size());
PyList_SET_ITEM(result, i, str);
}
return result;
}
#endif // HAVE_PYTHON
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: Filename::open_read // Function: Filename::open_read
// Access: Published // Access: Published

View File

@ -181,6 +181,9 @@ PUBLISHED:
int find_on_searchpath(const DSearchPath &searchpath); int find_on_searchpath(const DSearchPath &searchpath);
bool scan_directory(vector_string &contents) const; bool scan_directory(vector_string &contents) const;
#ifdef HAVE_PYTHON
PyObject *scan_directory() const;
#endif
bool open_read(ifstream &stream) const; bool open_read(ifstream &stream) const;
bool open_write(ofstream &stream, bool truncate = true) const; bool open_write(ofstream &stream, bool truncate = true) const;