Linux下遍历某文件夹下文件(不迭代进入子目录)
原文地址:http://www.wangzhongyuan.com/archives/487.html
以下是一个Linux/Unix下显示某一目录下文件列表的C程序,相当于最基本的ls命令的功能,显示的内容报告该目录下的子目录以及文件名:
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
int main(int argc,char *argv[])
{
DIR *dp;
struct dirent *dirp;
int n=0;
if (argc!=2)
{
printf("a single argument is required\n");
exit(0);
}
if((dp=opendir(argv[1]))==NULL)
printf("can't open %s",argv[1]);
while (((dirp=readdir(dp))!=NULL) && (n<=50))
{
if (n % 1 == 0) printf("\n");
n++;
printf("%10s ",dirp->d_name);
}
printf("\n");
closedir(dp);
exit(0);
}
如果只是显示该目录下的子目录名,则需要使用如下程序(其中还包括了一个对于子目录名的冒泡排序):
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
int main(int argc,char *argv[])
{
DIR *dp;
struct dirent *dirp;
struct stat buf;
char tempDirName[100];
char dirNames[100][100];
int n=0,i=0,j=0,dirCount=0;
if (argc!=2)
{
printf("a single argument is required\n");
exit(0);
}
strcat(tempDirName,argv[1]);//get the directory name
if((dp=opendir(argv[1]))==NULL)
printf("can't open %s",argv[1]);
while (((dirp=readdir(dp))!=NULL) && (n<=50))
{
//if (n % 1 == 0) printf("\n");
n++;
//printf("%10s ",dirp->d_name);
strcpy(tempDirName,"");//clear
strcat(tempDirName,argv[1]);//get the directory name
strcat(tempDirName,dirp->d_name);
if(IsDirectory(tempDirName))
{
//printf("\tDirectory!!!!");
strcpy(dirNames[dirCount],dirp->d_name);
//printf("\
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......
bin/mail会默认使用本地sendmail发送邮件,这样要求本地的机器必须安装和启动Sendmail服务,配置非常麻烦,而且会带来不必要的资源占用。而通过修改配置文件可以使用外部SMTP服务器,可以达到不使用sendmail而用外部的smtp服务器发送邮件的目的:
修改
/etc/mail.rc
set from=fromUser@domain.com
smtp=smtp.domain. ......
在我们在写程序的过程中,有些时候需要知道一些电脑的硬件信息,比如我们写一些需要注册的程序的时候,就需要得到某个电脑特定的信息,一般来说,网卡的物理地址是不会重复的,我们正好可以用它来做为我们识别一台电脑的标志.那如何得到网卡的物理地址呢?我们可以借助于ProcessBuilder这个类,这个类是JDK1.5新加的,以前也可以用Ru ......
一。linux系统的默认编码设置。
/etc/sysconfig/i18n
Controls the system font
settings. The language variables are used in /etc/profile.d/lang.sh. An
example i18n file:
LANG="zh_CN.GB18030"
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN ......