⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dl.cpp

📁 经过改进的C语言位操作功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
       int    m,
              h;

       for (int i = zero; i < num_files; i++) {
              cout << F[i]->name << "\t";

              if (strlen(F[i]->name) < eight)
                     cout << "\t";

              cout << form("%9lu",F[i]->size) << " ";

              cout << form("%02d",
                          ((F[i]->date >> five) & 0x0F))
                   << "/"
                   << form("%02d",(F[i]->date & 0x001F))
                   << "/"
                   << form("%02d",(((F[i]->date >> nine)
                                  & 0x7F) | 80));

              m = (F[i]->time >> five) & 0x3F;
              h = (F[i]->time >> eleven) & 0x1F;
              cout << " " << form("%2d",h)
                   << ":"
                   << form("%02d",m);

              if (h > 12)
                     cout << " pm";
              else
                     cout << " am";

              cout << "\n";
       }
}

//////////////////////////////////////////////////////////
//                                                      //
//            Class FileName::FileName()                //
//                           :FileList()                //
//                                                      //
//      Constructor                                     //
//                                                      //
//      Creates an instance of FileList via its con-    //
//      structor then sorts the directory structures    //
//      in ascending order according to File Names.     //
//                                                      //
//////////////////////////////////////////////////////////

inline FileName::FileName(const char *name,const int attrib)
                :FileList(name,attrib)
{
     qsort(F, num_files, sizeof(FIND *), Cmp_FileName);
}

//////////////////////////////////////////////////////////
//                                                      //
//            Class FileSize::FileSize()                //
//                           :FileList()                //
//                                                      //
//      Constructor                                     //
//                                                      //
//      Creates an instance of FileList via its con-    //
//      structor then sorts the directory structures    //
//      in ascending order according to File Sizes.     //
//                                                      //
//////////////////////////////////////////////////////////

inline FileSize::FileSize(const char *name,const int attrib)
                :FileList(name,attrib)
{
     qsort(F, num_files, sizeof(FIND *), Cmp_FileSize);
}

//////////////////////////////////////////////////////////
//                                                      //
//            Class FileDate::FileDate()                //
//                           :FileList()                //
//                                                      //
//      Constructor                                     //
//                                                      //
//      Creates an instance of FileList via its con-    //
//      structor then sorts the directory structures    //
//      in ascending order according to File Dates.     //
//                                                      //
//////////////////////////////////////////////////////////

inline FileDate::FileDate(const char *name,const int attrib)
                :FileList(name,attrib)
{
     qsort(F, num_files, sizeof(FIND *), Cmp_FileDate);
}

//////////////////////////////////////////////////////////
//                                                      //
//            Class FileExt::FileExt()                  //
//                          :FileList()                 //
//                                                      //
//      Constructor                                     //
//                                                      //
//      Creates an instance of FileList via its con-    //
//      structor then sorts the directory structures    //
//      in ascending order according to File Ext's.     //
//                                                      //
//////////////////////////////////////////////////////////

inline FileExt::FileExt(const char *name,const int attrib)
               :FileList(name,attrib)
{
     qsort(F, num_files, sizeof(FIND *), Cmp_FileExt);
}


//////////////////////////////////////////////////////////
//                                                      //
//      First_Object() creates a FileList object        //
//      that is not sorted, the default.  Implemented   //
//      as a seperate function allowing the destructor  //
//      to be called.                                   //
//                                                      //
//////////////////////////////////////////////////////////

inline void
First_Object()
{
       FileList test1;

       if (test1.Number() != error)
              test1.Print();
       else
              cerr << "\tNo files to print.\n";
       cout << "\n";
}

//////////////////////////////////////////////////////////
//                                                      //
//      Second_Object() creates a FileName object       //
//      that is sorted by the file name.  Implemented   //
//      as a seperate function allowing the destructor  //
//      to be called.                                   //
//                                                      //
//////////////////////////////////////////////////////////

inline void
Second_Object()
{
       FileName test2;

       if (test2.Number() != error)
              test2.Print();
       else
              cerr << "\tNo files to print\n";
       cout << "\n";
}

//////////////////////////////////////////////////////////
//                                                      //
//      Third_Object() creates a FileExt object         //
//      that is sorted by the file extension.           //
//      Implemented as a seperate function allowing     //
//      the destructor to be called.                    //
//                                                      //
//////////////////////////////////////////////////////////

inline void
Third_Object()
{
       FileExt test3;

       if (test3.Number() != error)
              test3.Print();
       else
              cerr << "\tNo files to print\n";
       cout << "\n";
}

//////////////////////////////////////////////////////////
//                                                      //
//      Fourth_Object() creates a FileDate object       //
//      that is sorted by the file date and time.       //
//      Implemented as a seperate function allowing     //
//      the destructor to be called.                    //
//                                                      //
//////////////////////////////////////////////////////////

inline void
Fourth_Object()
{
       FileDate test4;

       if (test4.Number() != error)
              test4.Print();
       else
              cerr << "\tNo files to print\n";
       cout << "\n";

}


//////////////////////////////////////////////////////////
//                                                      //
//      Main() tests FileList  FileName  FileExt        //
//                   FileDate  FileSize                 //
//                                                      //
//////////////////////////////////////////////////////////

main()
{
//
// Test the sorting methods
//

     First_Object();
     Second_Object();
     Third_Object();
     Fourth_Object();

     FileSize test5("*.*",FA_DIREC | FA_HIDDEN);

     if (test5.Number() != error)
          test5.Print();
     else
          cerr << "\tNo files to print\n";
     cout << "\n";

//
// Test the FileName_Match member
//

     cout << "Testing FileSize::FileName_Match()"
          << " for \"com\".\n\n";
     FIND test; 
     int *i = test5.FileName_Match("com");
     while (*i) {
          test = test5.Element(*i);
          int j = *i++;
          cout << "test5 file " << ++j << " is: "
               << test.name << "\n";
     };

//
// Test the Element and Number members
//

     test = test5.Element(two);
     cout << "\nThird element of test5 is: " << test.name
          << "\n\nTotal number of files = "
          << test5.Number() << "\n\n";

     cout << "\nFinished\n";

     exit(zero);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -