资源简介
unistd.h 头文件,可直接使用,应急下载
代码片段和文件信息
/*
* An example demonstrating recursive directory traversal.
*
* Compile this file with Visual Studio 2008 project vs2008.sln and run
* the produced command in console with a directory name argument. For
* example command
*
* find “C:\Program Files“
*
* might produce a listing with thousands of entries such as
*
* c:\Program Files/7-Zip/7-zip.chm
* c:\Program Files/7-Zip/7-zip.dll
* c:\Program Files/7-Zip/7z.dll
* c:\Program Files/Adobe/Reader 10.0/Reader/logsession.dll
* c:\Program Files/Adobe/Reader 10.0/Reader/LogTransport2.exe
* c:\Program Files/Windows NT/Accessories/wordpad.exe
* c:\Program Files/Windows NT/Accessories/write.wpc
*
* The find command provided by this file is only an example. That is
* the command does not provide options to restrict the output to certain
* files as the Linux version does.
*/
#include
#include
#include
#include “dirent.h“
static int find_directory (const char *dirname);
int
main(
int argc char *argv[])
{
int i;
int ok;
/* For each directory in command line */
i = 1;
while (i < argc) {
ok = find_directory (argv[i]);
if (!ok) {
exit (EXIT_FAILURE);
}
i++;
}
/* List current working directory if no arguments on command line */
if (argc == 1) {
find_directory (“.“);
}
return EXIT_SUCCESS;
}
/* Find files and subdirectories recursively */
static int
find_directory(
const char *dirname)
{
DIR *dir;
char buffer[PATH_MAX + 2];
char *p = buffer;
const char *src;
char *end = &buffer[PATH_MAX];
int ok;
/* Copy directory name to buffer */
src = dirname;
while (p < end && *src != ‘\0‘) {
*p++ = *src++;
}
*p = ‘\0‘;
/* Open directory stream */
dir = opendir (dirname);
if (dir != NULL) {
struct dirent *ent;
/* Print all files and directories within the directory */
while ((ent = readdir (dir)) != NULL) {
char *q = p;
char c;
/* Get final character of directory name */
if (buffer < q) {
c = q[-1];
} else {
c = ‘:‘;
}
/* Append directory separator if not already there */
if (c != ‘:‘ && c != ‘/‘ && c != ‘\\‘) {
*q++ = ‘/‘;
}
/* Append file name */
src = ent->d_name;
while (q < end && *src != ‘\0‘) {
*q++ = *src++;
}
*q = ‘\0‘;
/* Decide what to do with the directory entry */
switch (ent->d_type) {
case DT_LNK:
case DT_REG:
/* Output file name with directory */
printf (“%s\n“ buffer);
break;
case DT_DIR:
/* Scan sub-directory recursively */
if (strcmp (ent->d_name
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-04-07 14:18 tests\
目录 0 2014-04-07 14:18 tests\1\
文件 0 2014-04-07 14:18 tests\1\file
目录 0 2014-04-07 14:18 tests\1\dir\
文件 172 2014-04-07 14:18 tests\1\dir\readme.txt
目录 0 2014-04-07 14:18 tests\2\
文件 0 2014-04-07 14:18 tests\2\Testfile-1.2.3.dat
文件 56 2014-04-07 14:18 tests\2\file.txt
文件 7605 2014-04-07 14:18 tests\t-dirent.c
目录 0 2014-04-07 14:18 examples\
文件 4893 2014-04-07 14:18 examples\updatedb.c
文件 5625 2014-04-07 14:18 examples\locate.c
文件 2082 2014-04-07 14:18 examples\ls.c
文件 3469 2014-04-07 14:18 examples\find.c
文件 3502 2014-04-07 14:18 ChangeLog
目录 0 2014-04-07 14:18 vs2008\
目录 0 2014-04-07 14:18 vs2008\t-dirent\
文件 3543 2014-04-07 14:18 vs2008\t-dirent\t-dirent.vcproj
目录 0 2014-04-07 14:18 vs2008\locate\
文件 3541 2014-04-07 14:18 vs2008\locate\locate.vcproj
目录 0 2014-04-07 14:18 vs2008\updatedb\
文件 3547 2014-04-07 14:18 vs2008\updatedb\updatedb.vcproj
文件 2702 2014-04-07 14:18 vs2008\vs2008.sln
目录 0 2014-04-07 14:18 vs2008\ls\
文件 3529 2014-04-07 14:18 vs2008\ls\ls.vcproj
目录 0 2014-04-07 14:18 vs2008\find\
文件 3535 2014-04-07 14:18 vs2008\find\find.vcproj
目录 0 2014-04-07 14:18 include\
文件 22917 2014-04-07 14:18 include\dirent.h
相关资源
- STC12C5A60S2.H头文件
- vs2005下使用winhttp的头文件和lib文件
- CSerial串口标准函数头文件
- STC89C5xRC单片机头文件
- so文件的头文件
- elf的头文件
- algorithm 头文件 说明
- 基于51单片机can总线头文件定义
- dht11头文件
- vlc的lib、dll库和头文件
- ffmpeg 编译依赖头文件KHR、AMF、ffnvco
- OpenGL所需头文件和库文件.rar
- 头文件Delay.h网上很难找到的,建议后
- qedit.h头文件
- USB_HID_LIB
- OpenSSL头文件和lib64位
- visual studio 中如何设置头文件与源文件
- 现编译的lib_json,json包含头文件,l
-
libxm
l2 的windows版本库文件(包括头 - FMOD API (包含头文件,运行库)
- stdafx.h头文件免费
- libcurl 使用vs2010编译的动态库和静态库
- 编译好的libssl.liblibcrypto.lib 包含lib,
- stdint.h头文件
- stdbool.h头文件
- C8051F020初始化头文件
- lcd头文件(msp430)
- cs50.h 哈佛大学CS50课程头文件2016年秋
- 修改过得WinHttp头文件
- bios头文件
评论
共有 条评论