如何知道目录中有多少文件 [英] How to know how many files are into a directory

查看:72
本文介绍了如何知道目录中有多少文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助。我想读取包含在目录中的文本文件,

但是我的程序不知道包含了多少文件。


在bash中有'类似于(弄清楚)的东西


for i in< dirdo

....

完成


但我不知道如何在C中做同样的事情。你能告诉我代码片段吗?


- Antonio

解决方案

Antonio Maschio说:


我需要帮助。我想读取包含在目录中的文本文件,

但我的程序不知道包含多少文件。

http://c-faq.com/ - 见问题19.20。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:正常服务将尽快恢复。请不要

调整您的电子邮件客户端。


Antonio Maschio写道:

$ b $我需要帮助。我想读取包含在目录中的文本文件,

但是我的程序不知道包含了多少文件。


在bash中有'类似于(弄清楚)的东西


for i in< dirdo

...

完成


但我不知道如何在C中做同样的事情。你能告诉我代码片段吗?



标准C甚至没有文件或目录的概念,所以

最好的方式来做你自己的事情要求是使用你的C库提供的文件管理

函数,否则就是你的操作系统。

POSIX定义的函数在大多数现代的

操作系统。您可以使用这些例程通过

名称读取目录中的文件,然后尝试访问每个文件。


确切的方法通常根据您的不同而有所不同平台。在适当的组中要求更多

详细信息。这个小组只处理标准C.


On Sun,2006年11月19日14:50:57 +0100,在comp.lang.c,Antonio Maschio

< tb ** @ libero.itwrote:


>我需要帮助。我想读取包含在目录中的文本文件,
但是我的程序并不知道包含多少文件。



C没有任何处理目录的通用函数。

当然,大多数平台都有特定于系统的例程来执行此操作,

因此您需要在专业的平台组中询问。

-

马克麦金太尔


调试的难度是首先编写代码的两倍。

因此,如果你尽可能巧妙地编写代码,那么,根据定义,它不够聪明,无法调试它。

--Brian Kernighan


Hi, I need help. I want to read text files contained into a directory,
but my program is unaware of how many files are contained into.

In bash there''s something similar to (figure out)

for i in <dirdo
....
done

but I don''t know how to do the same in C. Can you show me snippets of code?

-- Antonio

解决方案

Antonio Maschio said:

Hi, I need help. I want to read text files contained into a directory,
but my program is unaware of how many files are contained into.

http://c-faq.com/ - see question 19.20.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.


Antonio Maschio wrote:

Hi, I need help. I want to read text files contained into a directory,
but my program is unaware of how many files are contained into.

In bash there''s something similar to (figure out)

for i in <dirdo
...
done

but I don''t know how to do the same in C. Can you show me snippets of code?

Standard C doesn''t even have the concept of files or directories, so
the best manner to do what you''re asking is to use the file management
functions offered by your C library or, failing that, your OS.
Functions defined by POSIX are widely implemented under most modern
OSes. You can use these routines to read the files in a directory by
name and then try to access each one.

The exact method often varies according to your platform. Ask for more
detail in an appropriate group. This group deals only with standard C.


On Sun, 19 Nov 2006 14:50:57 +0100, in comp.lang.c , Antonio Maschio
<tb**@libero.itwrote:

>Hi, I need help. I want to read text files contained into a directory,
but my program is unaware of how many files are contained into.

C doesn''t have any general functions for handling directories. Of
course most platforms do have system-specific routines for doing this,
so you need to ask in a group specialising in your platform.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan


这篇关于如何知道目录中有多少文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆