Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for hidden files under unix

Tags:

regex

cmake

I'm looking for a regex to match every file begining with a "." in a directory.

I'm using CMake (from CMake doc : "CMake expects regular expressions, not globs") and want to ignore every file begining with a dot (hidden files) BUT "\..*" or "^\..*" doesn't work :(

The strange thing : this works (thanks to rq's answer) and remove every hidden files and temp files ("~" terminated files)

file(GLOB DOT ".*")
file(GLOB TILD "*~")

set (CPACK_SOURCE_IGNORE_FILES "${DOT};${TILD}")

But I can't find the right thing to write directly into CPACK_SOURCE_IGNORE_FILES to have the same result!

Here is the "doc" of this variable.

like image 370
claf Avatar asked Dec 06 '25 15:12

claf


1 Answers

Sounds like GLOB is probably what you want.

Try this. Open a file "test.cmake" and add the following:

file(GLOB ALL "*")
file(GLOB DOT ".*")
file(GLOB NOTDOT "[^.]*")

message("All Files ${ALL}")
message("Dot files ${DOT}")
message("Not dot files ${NOTDOT}")

Then create a couple of test files:

touch .dotfile
touch notdot

Then run "cmake -P test.cmake". The output is:

All Files /tmp/cmake_test/.dotfile;/tmp/cmake_test/notdot;/tmp/cmake_test/test.cmake
Dot files /tmp/cmake_test/.dotfile
Not dot files /tmp/cmake_test/notdot;/tmp/cmake_test/test.cmake

This was tested with cmake 2.6.0.

like image 164
richq Avatar answered Dec 08 '25 08:12

richq