c++ 在windows 和 linux 獲得擴展名是(.xml)文件的文件名

//windows

#include <stdio.h>

#include <io.h>

#include <string>

 

int main()

{

    std::string sPath = "c://test//*.*";

    _finddata_t file;

    long lHandle;

    if((lHandle = _findfirst(sDir.c_str(), &file)) == -1L)

    {

        printf("can not find file!/n");

        return -1;

    }

 

    while(_findnext(lHandle, &file) == 0)

    {

         std::string s(file.name);

         std::string::size_type pos;

         if(std::string::npos != pos)

         {

             printf("file name:%s /n", s.substr(0, pos));

         }

     }

   

}

 

 

 

 

//linux

#include "stdio.h"

#include "dirent.h"

#include <string>

 

int main()

{

    std::string sPath = "/home/test/";

    struct dirent* pDirent = NULL;

    DIR* pDir;

    if(!(pDir = opendir(sDir.c_str())))

    {

         printf("can not open dir /n");

         return -1;

    } 

   

    while((ptr = readdir(dir)) != NULL)

    {

        std::string sName(pDirent->d_name);

        std::string::size_type pos;

    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

        if(std::string::npos != pos)

        {

            printf("file name:%s /n", sName.substr(0, pos));

        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章