I need to count the number of files in a directory, excluding subdirs and hidden files.
This works:
but includes .hidden files.
This excludes hidden files (filename beginning with '.' in this case):
but then I'm stuck counting subdirs again. There must be some way to combine those two 'if' statements but I haven't the slightest idea how.
This works:
Code:
numfiles = len([f for f in os.listdir(dir_name) if os.path.isfile(os.path.join(dir_name, f))])
but includes .hidden files.
This excludes hidden files (filename beginning with '.' in this case):
Code:
numfiles = len([f for f in os.listdir(dir_name) if f[0] != '.'])
but then I'm stuck counting subdirs again. There must be some way to combine those two 'if' statements but I haven't the slightest idea how.