On Aug 13, 6:09 pm, Peter Otten <__pete...@web.de> wrote: > blur959 wrote: > > Hi, I tried that, but it doesn't seem to work. My file directory has > > many different files extensions, and I want it to return me a number > > based on the number of files with similar files extensions. But when I > > tried running it, I get many weird numbers. Below is my code i had so > > far and the result. > > Use glob.glob() instead of os.listdir() if you are only interested in files > with a specific extension: > > >>> import glob > >>> len(glob.glob("*.py")) > > 42 > > Peter
Hi, I want to make it such that the user inputs a file extension and it prints the number of similar file extensions out. I tried doing this: directory = raw_input("input file directory") ext = raw_input("input file ext") file_list = len(glob.glob(ext)) print file_list And my result was this: 0 which it is suppose to be 11 May I know why? And how do I specify which directory it is searching the files extension from? I want the user to specify a directory and it searches the particular directory for the particular file extensions and prints the number out. Hope you guys could help. Thanks -- http://mail.python.org/mailman/listinfo/python-list