diff -r 40ad90580935 Lib/ntpath.py --- a/Lib/ntpath.py Thu Jun 02 23:40:24 2011 -0700 +++ b/Lib/ntpath.py Fri Jun 03 13:54:14 2011 -0500 @@ -672,3 +672,16 @@ def sameopenfile(f1, f2): """Test whether two file objects reference the same file""" return _getfileinformation(f1) == _getfileinformation(f2) + + +try: + # The genericpath.isdir implementation uses os.stat and checks the mode + # attribute to tell whether or not the path is a directory. + # This is overkill on Windows - just pass the path to FindFirstFile and + # check the attribute from there. + from nt import _isdir +except ImportError: + from genericpath import isdir as _isdir + +def isdir(path): + return _isdir(path) diff -r 40ad90580935 Modules/posixmodule.c --- a/Modules/posixmodule.c Thu Jun 02 23:40:24 2011 -0700 +++ b/Modules/posixmodule.c Fri Jun 03 13:54:14 2011 -0500 @@ -2819,6 +2819,40 @@ info.nFileIndexHigh, info.nFileIndexLow); } + +static PyObject * +posix__isdir(PyObject *self, PyObject *args) +{ + PyObject *opath; + char *path; + PyUnicodeObject *po; + WIN32_FIND_DATA find_data; + + if (PyArg_ParseTuple(args, "U|:_isdir", &po)) { + Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po); + + if (FindFirstFileW(wpath, &find_data) == INVALID_HANDLE_VALUE) + return win32_error("_isdir", NULL); + goto check; + } + /* Drop the argument parsing error as narrow strings + are also valid. */ + PyErr_Clear(); + + if (!PyArg_ParseTuple(args, "O&:_isdir", + PyUnicode_FSConverter, &opath)) + return NULL; + + path = PyBytes_AsString(opath); + if (FindFirstFileA(path, &find_data) == INVALID_HANDLE_VALUE) + return win32_error("_isdir", NULL); + +check: + if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} #endif /* MS_WINDOWS */ PyDoc_STRVAR(posix_mkdir__doc__, @@ -8055,6 +8089,7 @@ {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL}, {"_getfinalpathname", posix__getfinalpathname, METH_VARARGS, NULL}, {"_getfileinformation", posix__getfileinformation, METH_VARARGS, NULL}, + {"_isdir", posix__isdir, METH_VARARGS, NULL}, #endif #ifdef HAVE_GETLOADAVG {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},