
Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Тестовые примеры / ch7 / lstdir
.C #include "filebase.h"
#include "symfile.h"
#include "dirfile.h"
extern void long_list( ostream& ofs, const char* fname );
void show_list( ostream& ofs, char* fname, int deep);
/* program to implement the UNIX ls -lR command */
void show_dir( ostream& ofs, const char* fname )
{
dirfile dirObj(fname);
char buf[256];
ofs << "\nDirectory: " << fname << ":\n";
while (dirObj.read(buf,256)) // show all files in a directory
show_list(ofs, buf,0);
dirObj.seekg(0); // reset file pointer to beginning
while (dirObj.read(buf,256)) // Look for directory files
{
filebase fObj(buf,ios::in,0755); // define a filebase object
if (fObj.file_type()==DIR_FILE) // show sub-dir info
show_dir(ofs,buf);
fObj.close();
}
dirObj.close();
}
void show_list( ostream& ofs, const char* fname, int deep)
{
long_list( ofs, fname);
filebase fobj(fname,ios::in,0755);
if (fobj.file_type()==SYM_FILE) // symbolic link file
{
symfile *symObj = (symfile*)&fobj; // define a symfile object
ofs << " -> " << symObj->ref_path() << endl; // show reference path name
}
else if (fobj.file_type() == DIR_FILE && deep) // directory file
show_dir( ofs, fname ); // show directory content
}
int main( int argc, char* argv[])
{
while (--argc > 0) show_list( cout , *++argv, 1);
return 0;
}
Соседние файлы в папке ch7