pp \examples\pp \lang\summer py pp \examples\pp \pytools\search_all py herewe get back filenames from two different directories that match the spy patternbecause the directory name preceding this is wildcardpython collects all possible ways to reach the base filenames using os popen to spawn shell commands achieves the same effectbut only if the underlying shell or listing command doestooand with possibly different result formats across tools and platforms the os listdir call the os module' listdir call provides yet another way to collect filenames in python list it takes simple directory name stringnot filename patternand returns list containing the names of all entries in that directory--both simple files and nested directories--for use in the calling scriptimport os os listdir('['parts''pp ''random bin''spam txt''temp bin''temp txt'os listdir(os curdir['parts''pp ''random bin''spam txt''temp bin''temp txt'os listdir('parts'['part ''part ''part ''part 'thistoois done without resorting to shell commands and so is both fast and portable to all major python platforms the result is not in any particular order across platforms (but can be sorted with the list sort method or sorted built-in function)returns base filenames without their directory path prefixesdoes not include names or if presentand includes names of both files and directories at the listed level to compare all three listing techniqueslet' run them here side by side on an explicit directory they differ in some ways but are mostly just variations on theme for this task--os popen returns end-of-lines and may sort filenames on some platformsglob glob accepts pattern and returns filenames with directory prefixesand os list dir takes simple directory name and returns names without directory prefixesos popen('dir / parts'readlines(['part \ ''part \ ''part \ ''part \ 'glob glob( 'parts\*'['parts\\part ''parts\\part ''parts\\part ''parts\\part 'os listdir('parts'['part ''part ''part ''part 'of these threeglob and listdir are generally better options if you care about script portability and result uniformityand listdir seems fastest in recent python releases (but gauge its performance yourself--implementations may change over timedirectory tools