易截截图软件、单文件、免安装、纯绿色、仅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编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

Linux环境的AMP安装 PHP安装


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/ ......

php加入linux系统命令


假设php安装在/usr/local/php5/bin/php,初始在命令行执行PHP的时候要输入一长串的路径,eg:
$>/usr/local/php5/bin/php phpinfo.php
非常的麻烦,现在只需将php拷贝至usr/sbin目录即可直接使用php命令,eg:
$>cp /usr/local/php5/bin/php /usr/sbin/
$>php phpinfo.php
......

linux踢人技巧


linux系统root用户可强制踢制其它登录用户,
首先以root登录以便查看全部的在线用户信息,可用w命令查看登录用户信息
强制踢人命令格式:pkill -kill -t tty
解释:
pkill -kill -t  踢人命令
tty 所踢用户的TTY
如上踢出liu用户的命令为: pkill -kill -t pts/1
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号