How can I find path to given file?

后端 未结 6 1346
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 22:00

I have a file, for example \"something.exe\" and I want to find path to this file
How can I do this in python?

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 22:37

    This is really old thread, but might be useful to someone who stumbles across this. In python 3, there is a module called "glob" which takes "egrep" style search strings and returns system appropriate pathing (i.e. Unix\Linux and Windows).

    https://docs.python.org/3/library/glob.html

    Example usage would be:

    results = glob.glob('./**/FILE_NAME')
    

    Then you get a list of matches in the result variable.

提交回复
热议问题