- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我未能正确编写此函数。它应该递归地列出第一个参数提供的路径的内容(如 ls -R),但它停止得太快了。这是代码、预期输出和我得到的输出:
int browseDir (const char *path, const int *options)
{
char callingdir[MAXDIRLEN];
char currentdir[MAXDIRLEN];
getcwd(callingdir,MAXDIRLEN);
DIR *dirstream;
struct dirent *dir_entry;
struct stat file_data;
LIST subd_list = newList();
if (path == NULL)
strcpy(currentdir,callingdir);
else
strcpy(currentdir,path);
dirstream = opendir(currentdir);
printf("Listing: %s\n",currentdir);
chdir(currentdir);
if (dirstream == NULL)
{
perror("Error: cannot open directory\n");
return 0;
}
while((dir_entry = readdir(dirstream)) != NULL)
{
if (!ISSET_A_FLAG(*options))
{
if (dir_entry->d_name[0]=='.')
continue;
}
if (!ISSET_S_FLAG(*options))
{
stat(dir_entry->d_name, &file_data);
printStat(&file_data);
}
printf("%s ",dir_entry->d_name);
printf("\n");
if (ISSET_R_FLAG(*options) && (dir_entry->d_type & DT_DIR) && strcmp(dir_entry->d_name,".") && strcmp(dir_entry->d_name,".."))
addNode(subd_list, dir_entry->d_name);
}
closedir(dirstream);
while(!isEmpty(subd_list))
{
browseDir((*subd_list)->data, options);
delNode(subd_list);
}
chdir(callingdir);
return 0;
}
使用 ls -Rli 输出(预期)
tod@iTod:~/Dropbox/programming/SO/myshell2$ ls -lRi /home/tod/programming/shelldeb
/home/tod/programming/shelldeb:
totale 52
1150597 drwxr-xr-x 3 tod tod 4096 ott 18 02:34 bin
1054396 -rw-rw-r-- 1 tod tod 7696 ott 18 15:21 commands.c
1045205 -rw-rw-r-- 1 tod tod 1233 ott 16 23:14 commands.h
1045208 -rw-rw-r-- 1 tod tod 952 ott 18 17:10 list.c
1057517 -rw-rw-r-- 1 tod tod 244 ott 18 15:22 list.h
1055205 -rw-r--r-- 1 tod tod 487 ott 18 02:36 main.c
1150595 drwxr-xr-x 3 tod tod 4096 ott 18 02:34 obj
1057590 -rw-rw-r-- 1 tod tod 1213 ott 18 09:33 parsing.c
1057622 -rw-rw-r-- 1 tod tod 193 ott 18 09:33 parsing.h
1055154 -rw-rw-r-- 1 tod tod 1368 ott 18 02:51 shelldeb.cbp
1057688 -rw-rw-r-- 1 tod tod 665 ott 18 15:22 shelldeb.depend
1057721 -rw-rw-r-- 1 tod tod 1413 ott 18 23:20 shelldeb.layout
/home/tod/programming/shelldeb/bin:
totale 4
1150598 drwxr-xr-x 3 tod tod 4096 ott 20 14:02 Debug
/home/tod/programming/shelldeb/bin/Debug:
totale 4
1150684 drwxrwxr-x 4 tod tod 4096 ott 20 14:02 r55
/home/tod/programming/shelldeb/bin/Debug/r55:
totale 8
1150685 drwxrwxr-x 2 tod tod 4096 ott 20 14:03 tmpfolder
1150686 drwxrwxr-x 2 tod tod 4096 ott 20 14:02 tmpfolder2
/home/tod/programming/shelldeb/bin/Debug/r55/tmpfolder:
totale 0
1045360 -rw-rw-r-- 1 tod tod 0 ott 20 14:03 myfile
/home/tod/programming/shelldeb/bin/Debug/r55/tmpfolder2:
totale 0
/home/tod/programming/shelldeb/obj:
totale 4
1150596 drwxr-xr-x 3 tod tod 4096 ott 20 14:01 Debug
/home/tod/programming/shelldeb/obj/Debug:
totale 20
1046334 -rw-rw-r-- 1 tod tod 15088 ott 18 17:10 commands.o
1046232 -rw-rw-r-- 1 tod tod 0 ott 20 14:01 comment.txt
1150683 drwxrwxr-x 2 tod tod 4096 ott 20 14:02 tmpfolder
/home/tod/programming/shelldeb/obj/Debug/tmpfolder:
运行我的 shell 的当前输出:
> list /home/tod/programming/shelldeb -r
Listing: /home/tod/programming/shelldeb
1057517 -rw-rw-r-- 1 1000 1000 244 list.h
1054396 -rw-rw-r-- 1 1000 1000 7696 commands.c
1057590 -rw-rw-r-- 1 1000 1000 1213 parsing.c
1150597 drwxr-xr-x 3 1000 1000 4096 bin
1045208 -rw-rw-r-- 1 1000 1000 952 list.c
1055154 -rw-rw-r-- 1 1000 1000 1368 shelldeb.cbp
1150595 drwxr-xr-x 3 1000 1000 4096 obj
1045205 -rw-rw-r-- 1 1000 1000 1233 commands.h
1057688 -rw-rw-r-- 1 1000 1000 665 shelldeb.depend
1057721 -rw-rw-r-- 1 1000 1000 1413 shelldeb.layout
1057622 -rw-rw-r-- 1 1000 1000 193 parsing.h
1055205 -rw-r--r-- 1 1000 1000 487 main.c
Listing: obj
1150596 drwxr-xr-x 3 1000 1000 4096 Debug
Listing: Debug
1046232 -rw-rw-r-- 1 1000 1000 0 comment.txt
1150683 drwxrwxr-x 2 1000 1000 4096 tmpfolder
1046334 -rw-rw-r-- 1 1000 1000 15088 commands.o
Listing: tmpfolder
1054413 -rw-rw-r-- 1 1000 1000 0 tmp.txt
最佳答案
我终于设法以一种非常简单的方式编写了一个递归列表函数。我在 c 标准库中找到了函数 nftw() ,基本上它完成了所有工作。这是感兴趣的人的代码:
static int list (const char *path)
{
char calling_dir[MAXDIRLEN];
DIR *dirstream;
struct dirent *dir_entry;
struct stat file_data;
getcwd(calling_dir,MAXDIRLEN);
dirstream=opendir(path);
if (dirstream == NULL)
{
perror("Error: cannot open directory\n");
return -1;
}
chdir(path);
while((dir_entry = readdir(dirstream)) != NULL)
{
if (!ISSET_A_FLAG(options))
{
if (dir_entry->d_name[0]=='.')
continue;
}
if (!ISSET_S_FLAG(options))
{
stat(dir_entry->d_name, &file_data);
printStat(&file_data);
}
printf("%s ",dir_entry->d_name);
printf("\n");
}
closedir(dirstream);
chdir(calling_dir);
return 0;
}
static int list_R (const char *entry_path, const struct stat *entry_stat,int typeflag,struct FTW *ftwbuf)
{
int status;
if(typeflag & FTW_D)
{
printf("\nContent of %s : \n",entry_path);
status=list(entry_path);
}
if (status == -1)
return status;
return 0;
}
使用这两个函数,您只需执行 printstat() 即可在目录条目上打印信息。对 nftw(path,list_R,1,ftw_flags) 的简单调用;在设置 FTW_PHYS 标志后完成这项工作。
关于c - 递归列出目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19437223/
如何从单个输入字段中的逗号分隔值输出列表(无论是作为单个值还是作为数组)? 示例 用户在文本输入字段中输入以下内容:Steve、Bruce、Matt、Natasha、Peter 结果: 史蒂夫 布鲁斯
如何列出与 Jena 中的实例关联的所有对象属性? 例如:Person 有一个名为“hasVehicle”的对象属性,它与类 Vehicle 相关联 最佳答案 合适的 Jena 方法是 OntClas
如何列出与 Jena 中的实例关联的所有对象属性? 例如:Person 有一个名为“hasVehicle”的对象属性,它与类 Vehicle 相关联 最佳答案 合适的 Jena 方法是 OntClas
我知道 Python 是一种动态语言,但下面的代码让我很困扰。 我有下面的简单程序,它有一些辅助函数来包装命令执行。 EventLoaderToVerticaHelper 是一个有两个方法的辅助类,所
我有以下代码 public void saveProjects(List proj) throws DatabaseException { for (Project listItems: pr
我有一个列表,其中元素是: struct element { double priority; int value;
我看到对于 pull 请求的提交,根据文档最大限制为 250:List commits on a Pull Request如果 pull 请求超过 250 次提交,则建议使用另一个端点:List Co
我是 django 的新手,我想列出一个 django 项目的应用程序,例如: FeinCMS 我知道 startapp 会为应用程序创建目录结构。请问有没有函数或者文件可以获取应用列表。 以Fein
你能列出所有在 Hibernate 框架中使用的设计模式吗? 我了解一些设计模式,如 DAO、ORM 等。 如果可能的话,一些例子。 最佳答案 Hibernate 中使用的设计模式: 领域模型模式——
我正在尝试在终端中使用 psql 来查找数据库中所有可为空的列。如果我使用 select * from information_schema.check_constraints; 我得到如下信息 c
您可以使用以下步骤列出 WSO2 碳基产品使用的所有管理服务。 使用 OSGI 控制台启动服务器。转至 /bin 使用命令 shell 。 i) 例如:Linux sh wso2server.s
我想列出数据库中的所有表名。我的应用程序必须独立于 DBMS。不同的 DBMS 有不同的命令来列出表,例如: PstgreSQL: SELECT * FROM pg_catalog.pg_table
主要是为了我自己的启发,我试图列出当前 Emacs session 中加载的所有全局变量。我正在考虑做的是生成一个包含所有列出的功能的 HTML 文件。当然,定义函数、var 等的文件也很有用。 em
我如何定义 lists:append具有列表理解功能? 我想要类似的东西 1> append([[1, 2, 3], [a, b], [4, 5, 6]]). [1,2,3,a,b,4,5,6] 最佳
使用以下 Powershell 代码段,我可以获取当前用户的组成员名称: $groups = [System.Security.Principal.WindowsIdentity]::GetCurre
如何列出 Docker 容器的所有卷?我知道它应该很容易获得,但我找不到方法。 另外,是否可以获取已删除容器的卷并将其删除? 最佳答案 您可以使用 docker ps,获取容器 ID 并写入: $ d
来自微软独库: The "\\.\" prefix will access the Win32 device namespace instead of the Win32 file namespace
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: Finding all Namespaces in an assembly using Reflection (Do
是否有命令行选项可以列出您的 Cucumber 测试套件中的所有标签? 例如,我想要这样的东西: cucumber --show-tags foo.feature 那会给我类似的东西: @ci @de
有没有一种快速的方法来列出为数据库定义的所有实际上没有被任何字段使用的 Firebird 域?我有一个包含许多表和许多域的大型数据库,似乎其中很多不再使用,所以我想是时候进行清理了! 我认为这可以通过
我是一名优秀的程序员,十分优秀!