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 ......
Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......
3、PHP安装
1)还是下载源码包,如:php-5.1.1.tar.gz,下载地址:http://www.php.net
2)解压缩,>tar -zxvf php-5.1.1.tar.gz
3)进入php-5.1.1,>cd php-5.1.1
4)安装配置,>./configure --prefix=/opt/php
--with-apxs2=/opt/apache/bin/apxs --with-mysql=/opt/mysql
--with-mysqli=/opt/mysql/bin/ ......
Linux下mbstring安装
1、用cd命令进入php的源代码目录下的etc/mbstring目录下,如“/src/php5.2.5”,即“cd /src/php5.2.5”;
2、>/usr/local/php/bin/phpize (假设php安装在/usr/local/php目录下)
3、编译配置,>./configure --with-php-config=/usr/local/php/bin/php-config
4、执行 ......
1、下载phpMyAdmin至web服务器目录并重命名为:phpmyadmin。假设服务器目录为www,则存放位置为www/phpmyadmin,访问路径为http://localhost/phpmyadmin
2、复制"/phpmyadmin/libraries/"目录下的"config.default.php"文件至"/phpmyadmin/"目录下,并重命名为"config.inc.php"
3 ......