易截截图软件、单文件、免安装、纯绿色、仅160KB

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("\


相关文档:

实战Linux Bluetooth编程(三) HCI层编程

1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI)  就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......

Linux环境的AMP安装 APACHE安装


2、APACHE的安装
1)当然还是下载源码包,如:httpd-2.0.55.tar.gz,地址自己找……
2)解压缩,>tar -zxvf httpd-2.0.55.tar.gz
3)进入解压后的httpd-2.0.55,>cd httpd-2.0.55
4)安装配置,>./configure --prefix=/opt/apache --enable-cgi
5)编译,>make
6)安装,>make install ......

Linux环境的AMP安装 mcrypt安装


4、mcrypt安装
1)安装mcrypt之前,必须安装libmcrypt和mhash,先去http://www.sourceforge.net
下载Libmcrypt,mhash,mcrypt安装包
2)先安装Libmcrypt
     >tar -zxvf libmcrypt-2.5.8.tar.gz
     >cd libmcrypt-2.5.8
     >./conf ......

Linux环境的AMP安装 MSSQL扩展安装


Linux要安装mssql扩展,必须首先安装freetds,安装过程如下:
1、假设源文件目录为/webServ,安装目录为/opt/freetds。
1) >cd /webServ
2) 下载, >wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
3) 解压, >tar -zxvf freetds-stable.tgz
4) 进入, >cd freetds-0。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号