fnmatch.fnmatch use a pattern to exclude sub directories

  fnmatch, python, unix, wildcard, windows

I have a directory structure like this

root/
    - some.jar
    - another.jar
    subDirectory/
                -some1.jar

I only want to get the files in the root and not the subDirectory (some.jar and another.jar).

I have also tried the following pattern but I was trying to do it without specifying the name of the subDirectory in the pattern. See here with directory name specified.

I have also used pattern like ‘*.jar’ but it also includes the subDirectory file.

Any suggestions?

Source: Windows Questions

LEAVE A COMMENT