XiaoHui.Net 笑汇程序员论坛Visual C++ 讨论区

   怎样得到一个目录下的所有rmvb文件?


页: [1]

ghqxx2006-10-13 10:38
怎样得到一个目录下的所有rmvb文件?

跪求,给定一个操作目录,我想得到该文件夹下所有的电影文件,请问如何写代码,或者该用什么样的函数。


iceeden2007-5-5 05:21
[code]
BOOL CImgcheck1Dlg::serchFilename(CString currentPath)
{
        char svPath[MAX_PATH+1];
        lstrcpyn(svPath,currentPath,MAX_PATH-1);
        if(svPath[lstrlen(svPath)-1]=='\\')
                lstrcat(svPath, "*.rmvb");
        HANDLE hFind;
        WIN32_FIND_DATA finddata;
        hFind=FindFirstFile(svPath, &finddata);
        if(hFind==INVALID_HANDLE_VALUE)
                return FALSE;
        do
        {
                CString filename = finddata.cFileName;
                if(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                {
                }
                else
                {
                        filename.MakeLower();
                        {
                                try
                                {
                                        filename = currentPath + filename;
AfxMessageBox(filename);//填加你要处理的过程
                                }
                                catch(...)
                                {
                                }
                        }
                }
        } while(FindNextFile(hFind, &finddata));
        FindClose(hFind);
        return FALSE;
}


调用:
serchFilename("c:\\mydata\\movie\\");
[/code]

warrior2007-8-16 10:25
嗯,主要使用FindFirstFile和FindNextFile。


gwq853875662007-10-12 05:30
判断后缀是否为rmvb

#include <iostream>
#include <string>
using namespace std;
//函数的作用是取得全文件名的后缀,并判断后缀是否为rmvb如果是返回0 不是返回非0
//这里的fileName参数可以根据需要用字符指针替代,记得将里面的转化去掉
int  getPostfixName(string fileName)
{
        //strrchr 返回最后一次出现的 某字符(这里为'.')的地址(地址是从某字符开始的)
        char* pPostfixName = strrchr(fileName.c_str(),'.');
       
        if(0!= strcmp(++pPostfixName,"rmvb"))
        {
                return -1;
        }

        return 0;
}

void main()
{
        string fileName;
        fileName="gwq.rmvb";
        //如果函数的返回值为0表示该文件是rmvb文件
        cout<<getPostfixName(fileName)<<endl;
}


查看完整版本: 怎样得到一个目录下的所有rmvb文件?