1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Validate a globed-like path

Discussão em 'Python' iniciado por Stack, Setembro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am writing a API for a program. The program has a native support of "globed" paths such as img-0*.png. I would like to know how to be sure that there is at least a file satisfying that pattern, a kind of is_globable(path) method.

    path = 'img-0*.png'

    if os.path.isfile(path):
    pass
    elif is_globable(path):
    pass
    else:
    raise Exception(...)


    Neither glob or pathlib provide such a functionality. The most related method I found is pathlib.PurePath.full_match but solves the opposite problem.

    Continue reading...

Compartilhe esta Página