If you want to search for files with a specific name (e.g. “example”), but you don’t know the file extension, you can use the glob module to search for files with a specific pattern. The glob module provides a function called glob() that can be used to search for files with a specific pattern in a directory.

Here is an example of how to use glob to search for all files with the name “example” and a file extension of “vtk” or “stl” in the current directory:

import glob

files = glob.glob("example.*")
print(files)

You can use glob function to search for files in a specific directory, by passing the directory path as the first argument.

import glob

directory_path = '/path/to/directory'
files = glob.glob(directory_path + "/example.*")
print(files)

You can also use glob to search for files with multiple extensions, by using the ? character as a wildcard for the file extension.

import glob

files = glob.glob("example.*.{vtk,stl}")
print(files)

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *