diff -r 13e47495a7be Lib/pathlib.py --- a/Lib/pathlib.py Mon Nov 25 09:40:27 2013 +0100 +++ b/Lib/pathlib.py Mon Nov 25 11:24:26 2013 +0100 @@ -962,6 +962,20 @@ if self._closed: self._raise_closed() + def iterfiles(self): + """ Iterate over the files (without directories) in this directory. """ + for f in self.iterdir(): + if f.is_file(): + yield f + + def iterdirs(self): + """Iterate over the directories in this directory. Does not yield any + result for the special paths '.' and '..'. + """ + for f in self.iterdir(): + if f.is_dir(): + yield f + def glob(self, pattern): """Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given pattern. diff -r 13e47495a7be Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py Mon Nov 25 09:40:27 2013 +0100 +++ b/Lib/test/test_pathlib.py Mon Nov 25 11:24:26 2013 +0100 @@ -1187,6 +1187,26 @@ self.assertIn(cm.exception.errno, (errno.ENOTDIR, errno.ENOENT, errno.EINVAL)) + def test_iterfiles(self): + P = self.cls + p = P(BASE) + it = p.iterfiles() + paths = set(it) + expected = ['fileA'] + if not symlink_skip_reason: + expected += ['linkA'] + self.assertEqual(paths, { P(BASE, q) for q in expected }) + + def test_iterdirs(self): + P = self.cls + p = P(BASE) + it = p.iterdirs() + paths = set(it) + expected = ['dirA', 'dirB', 'dirC'] + if not symlink_skip_reason: + expected += ['linkB'] + self.assertEqual(paths, { P(BASE, q) for q in expected }) + def test_glob_common(self): def _check(glob, expected): self.assertEqual(set(glob), { P(BASE, q) for q in expected })