- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这只是一个用下划线替换空格的简单程序。我找到了一个 bash 脚本可以做到这一点,但速度很慢。据我了解,我想要一个深度优先搜索,并且我希望在后序目录上调用我的remove_space函数(在备份的过程中)。我对术语的理解正确吗?现在情况如何,我必须多次调用该程序才能更改所有名称。我认为因为它在返回输入目录时按预序更改了目录名称,所以它找不到它,因为它正在寻找旧名称。你知道我如何在 postoder 中的目录上调用我的函数吗?
提前致谢!
int main(int argc, char *argv[]) {
char * const *old_name = (argv + 1);
int opts = 0;
FTS *ftsp;
FTSENT *scan;
if (argc < 2) {
fprintf(stderr, "usage: %s <dir path>\n", *argv);
exit(1);
}
opts |= (FTS_PHYSICAL | FTS_SEEDOT | FTS_XDEV);
ftsp = fts_open(old_name, opts, NULL);
while ((scan = fts_read(ftsp)) != NULL) {
if (scan->fts_info == FTS_DOT)
continue;
remove_space(scan->fts_name);
printf("%s\n", scan->fts_name);
}
fts_close(ftsp);
return 0;
}
int remove_space(const char *old_str) {
char new_str[strlen(old_str)];
int i = 0;
int j = 0;
while (*(old_str + i)) {
if (isalnum(*(old_str + i))) {
while (*(old_str + i)) {
if (*(old_str + i) == SPACE)
*(new_str + j) = UNDER_SCORE;
else
*(new_str + j) = *(old_str + i);
i++;
j++;
}
} else {
i++;
}
}
*(new_str + j) = '\0';
rename(old_str, new_str);
return 0;
}
最佳答案
正如手册页所述,在 *fts_read* 上:
Directories (that are readable and do not cause cycles) are visited at least twice, once in preorder and once in postorder.
因此,一种方法是测试这是否是一个目录,并在第一次遇到它时跳过它。
手册页中的 *fts_set* 中描述了另一种方法,其中包含选项 FTS_AGAIN:
Normal use is for postorder directory visits, where it causes the directory to be revisited (in both preorder and postorder) as well as all of its descendants.
顺便说一句,如果性能是您的问题,您可以使用 *fts_children*,并带有 FTS_NAMEONLY 选项
关于linux - 使用 fts(3) 函数重命名文件和目录。仅第一级发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22728099/
您好,感谢您的关注! 我正在搜索包含某些带有全文搜索的字符串的文章,如下所示: SELECT * FROM Articles_fts WHERE body MATCH 'monkey OR banan
我已经下载了最新的 SQLite 3.7.15.2 shell (Win32),并尝试完全按照 http://sqlite.org/fts3.html#section_3 中的说明执行 FTS 示例之
当我在 sqlite 引擎(android 或 sqlitebrowser)中执行以下查询时,它会抛出一个异常,指出无法在请求的上下文中使用函数 MATCH。 select a.Body1,
我有一个 ~32mb 的大数据库,其中包含 4 种语言的大量文本。包括阿拉伯语和乌尔都语。我需要以最有效的方式(速度和大小)搜索此文本。 我正在考虑 FTS,并试图找出实现它的方法。现在我正在阅读 h
我在我的应用程序中使用 SQLite FTS3 表。但使用 FTS 表搜索对非英文字符区分大小写。 是否有简单的方法使对 unicode 符号的搜索支持不区分大小写? 最佳答案 当您在 FTS 表中插
我知道我们可以在财务工具箱中使用“tomonthly”函数,但这会返回一个默认的每月数据,取每个月的最后一个工作日。 如果我想要每个月的第一个工作日怎么办? 我已经尝试通过以下方式将“ED”设置为 1
SQLite FTS 的文档 implies应使用 INSERT、UPDATE、DELETE 等填充和更新 FTS 表。 这就是我正在做的 - 添加行,删除它们等,但最近我注意到,一旦我创建了 FTS
我在 SQLite 中使用 FTS,我有数据: abc def go to to go jdk sqlite let go go on going to not going 我使用查询:select
我正在尝试创建一个类似 Android 的应用程序,并希望允许快速搜索,因此正在研究适用于 Android 的 sqlite 的 FTS。我知道如何创建它,但想知道一些事情: Table_words
我刚刚发现可以使用虚拟表来搜索数据库内容。然而,我已经坐了两天了,我想我每过一个小时就变得更愚蠢。有人可以给我提供一个简单的例子来说明如何做到这一点吗? 这就是我所在的位置:我有一个数据库类: pub
我正在使用 MySQL 5.6.10 的 InnoDB FTS,并且想更改 boolean 运算符的默认行为。 Note In implementing this feature, MySQL use
我无权访问 information_schema。我可以获得数据库的 FTS 索引列表吗?以下查询有效,但由于权限不足而失败。 SELECT i.name as index_name FROM inf
假设我有以下伪模式,其中 1-many 关系是使用 Postgres 数组建模的: CREATE TYPE quotes AS ( text CHARACTER VARYING, is_di
在一个项目中,模式是这样的: id , key, value key和 value列是 varchar,表是 InnoDB . 用户可以根据键值对进行搜索……在 MySQL 中查询的最佳方式是什么?我
如标题所述,您如何知道查询是否使用 FTS 索引? 通常显示using index condition。 我的查询是: SELECT * FROM news WHERE MATCH(news_titl
假设搜索输入是“what is”。这将匹配“whatever it is”和“what is”,这是确切的短语。现在,如何在排序中将确切的短语排在第一位? 从昨天开始我就一直在思考这个问题,我一直在想
我正在尝试进行快速文本搜索,以便完全匹配在前,部分匹配在后。 我创建了一个可在 SQLiteStudio 中使用的查询: SELECT value, 1 AS _order FROM glossfts
我的问题的措辞来自博文末尾的评论Android Quick Tip: Using SQLite FTS Tables .正如标题所暗示的那样,该帖子介绍了如何在您的 Android 应用程序中创建和查
我正在使用 SQLite FTS 在文本文章中查找文本: SELECT count(*) FROM enrondata1 WHERE content MATCH 'linux'; 这将返回包含 lin
有没有办法在 SQLite 中创建一个预填充了来自 SELECT 查询的数据的 FTS 表? 我知道可以创建一个用 SELECT 中的数据预填充的常规表:CREATE TABLE foo AS SEL
我是一名优秀的程序员,十分优秀!