tags:

views:

801

answers:

4

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.

+1  A: 

Using standard regex syntax:

^\..*

Since CMake apparently doesn't like this, it may use something like:

^\\..*

That's just a guess, though, since I don't have/use CMake.

Hank Gay
I need a regex to use in CMake, your expression gives me the result : "CMake Error: Invalid escape sequence \."
claferri
maybe you nead to add slashes /^\..*/
Sergej Andrejev
CMake is doing you wrong, then. That's the standard regex syntax to do what you asked. Maybe it requires you to use ^\\..* instead?
Hank Gay
doesnt work neither :(
claferri
A: 

You need to escape it.

^\..*
Chase Seibert
A: 

Try this:

^[.].*
Alan Moore
doesn't work neither (but doesn't produce error)
claferri
+1  A: 

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.

rq
Even if "CMake expects regular expressions, not globs", your solution help me do what I want using CMake variables to list all files I want to ignore. What is weird : I can't find the right thing to write directly into the variable in order to avoid listing the file using your solution. Thx anyway!
claferri