linux 平台递归读取读取所有文件夹和文件名称
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<sys/types.h>
#include<dirent.h>
#define MAX 1024
char path[100];
char *strmin(char *des,const char *min)
{
int i=strlen(des);
int j=strlen(min);
if(i>=j)
{
strncpy(des+i-j,"\0",1);
}
return des;
}
void print(char *path,char *tmpname)
{
struct stat buf;
if(stat(path,&buf)<0)
{
printf("stat error!\n");
return;
}
struct dirent *filename;
if(S_ISDIR(buf.st_mode))
{
DIR *dp;
dp=opendir(path);
while(1)
{
filename=readdir(dp);
if(filename == NULL)
{
strmin(path,tmpname);
closedir(dp);
return ;
}
else
{
if(strcmp(filename->d_name,".")==0 ||strcmp(filename->d_name,"..")==0)
continue;
printf("%s\n",filename->d_name);
strcat(path,"/");
strcat(path,filename->d_name);
print(path,filename->d_name);
strmin(path,"/");
}
}
}
else
{
int fd;
fd=open(path,O_RDWR);
char buf[MAX];
int size;
while(1)
{
size=read(fd,buf,MAX);
if(size==0)
{
close(fd);
break;
}
}
strmin(path,tmpname);
}
}
int
相关文档:
转贴地址:http://www.linuxsir.org/main/?q=node/137
总结:
zhy2111314
来自:
LinuxSir.Org
整理:
北南南北
摘要:
本文是find 命令的详细说明,可贵的是针对参数举了很多的实例,大量的例证,让初学者更为容易理解;本文是zhyfly兄贴在论坛中;我对本文进行了再次整理,为方便大家阅读;
目录
版权声明
前 ......
pgrep 是通过程序的名字来查询进程的工具,一般是用来判断程序是否正在运行。在服务器的配置和管理中,这个工具常被应用,简单明了;
用法:
#ps 参数选项 程序名
常用参数
-l 列出程序名和进程ID;
-o 进程起始的ID;
-n 进程终止的ID;
举例:
[root@localhost ~]# pgrep ......
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<net/if.h>
static char *bad_interface_names[] = {
"lo:",
"lo",
&n ......
语 法:ifconfig [网络设备][down up -allmulti -arp -promisc][add<地址>][del<地址>][<网络设备类型> <硬件地址>][io_addr][irq ][media<网络媒介类型>][mem_start<内存地址>][metric<数目>][mtu<字节>][netmask<子网掩码>][tunnel<地址>][-broadc ......
/*通过鼠标拖放文件到制定控件中,并判断是否为文件,如果是,则调用文件发送方法ChatFrame.SendFile(finalpath);
*/
class TextDropTargetListener implements DropTargetListener
{
CODER Coder = new CODER();
CHAT_FRAME ChatFrame;
/**
Constructs a listener.
@param aTextArea the ......