本文介绍了Unix下隐藏文件的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个正则表达式来匹配每个以。开头的文件。

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

我正在使用CMake(来自CMake doc: CMake需要正则表达式,而不是glob),并且想忽略每个以点开头的文件(隐藏文件),但 \ .. * ^ \ .. * 不起作用:(

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 :(

这很奇怪:这有效(由于rq的)并删除所有隐藏文件和临时文件(〜终止文件)

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}")

但是我找不到直接写到 CPACK_SOURCE_IGNORE_FILES 可以得到相同的结果!

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

这里是 。

推荐答案

类似于GLOB的声音可能就是您想要的。

Sounds like GLOB is probably what you want.

尝试一下。打开文件 test.cmake并添加以下内容:

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

然后运行 cmake -P test.cmake。输出为:

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

已使用cmake 2.6.0进行了测试。

This was tested with cmake 2.6.0.

这篇关于Unix下隐藏文件的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 17:35