Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

Is there a way to find directory path using regex on cmake?

I looked up all over but couldn't find an answer for this.

Let's say I have a directory path like this : {MY_PATH}/AAA_unknown_pattern/other/inside/files.../

How can I get path "{MY_PATH}/AAA_unknown_pattern" without knowing "unknown_pattern" and other inside files;

MY_PATH is known and i also know the directory starts with "AAA_"

I tried something like this using regex but it doesn't work:

get_filename_component(TEST "${MY_PATH }/^AAA_" DIRECTORY)

message("test: ${TEST}") shows "C:/path/until/here/^AAA_" instead of correct path.

The reason of all this is because I want to split after and get unknown_pattern . Thank you.

question from:https://stackoverflow.com/questions/65904787/is-there-a-way-to-find-directory-path-using-regex-on-cmake

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Thanks to Tsyvarev I could figure it out using

file(GLOB TEST RELATIVE ${MY_PATH} ${MY_PATH}/AAA*)
MESSAGE("TEST=${TEST}")

it prints the whole AAA{other_chars} directory name


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...