C program under Linux ------ Dir Scan

zhaozj2021-02-16  100

#include

#include

#include

#include

#include

#include

Void PrintDir (Char * Dir, INT Depth)

{

DIR * DP;

Struct Dirent * Entry;

Struct stat statbuf;

IF ((DP = OpenDir (DIR)) == NULL)

{

FPRINTF (2, "Can NOT OPEN DIRECTORY: S / N", DIR);

Return;

}

CHDIR (DIR);

While ((entry = readir (dp))! = null)

{

LSTAT (entry-> d_name, & statbuf);

IF (S_ISDIR (STATBUF.ST_MODE))

{

IF (strcmp (".", entry-> d_name) == 0 || Strcmp ("..", entry-> d_name) == 0)

{

CONTINUE;

}

Printf ("% * s% s // n", defth, "", entry-> d_name);

PrintDir (entry-> d_name, depth 4);

}

Else Printf ("% * S% S / N", DEPTH, "" ", Entry-> D_Name);

}

chdir ("..");

CloseDir (DP);

}

int main ()

{

Printf ("Directory Scan Of / Home / Lzy / PROG_C: / N");

PrintDir ("/ Home / Lzy / PROG_C", 0);

Printf ("DONE!");

exit (0);

}

转载请注明原文地址:https://www.9cbs.com/read-10788.html

New Post(0)