首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎么打开一个大文件夹中的多个同名文件,并进行相同的读写操作阿

2012-03-03 
如何打开一个大文件夹中的多个同名文件,并进行相同的读写操作阿如何打开一个大文件夹中的多个同名文件,并

如何打开一个大文件夹中的多个同名文件,并进行相同的读写操作阿
如何打开一个大文件夹中的多个同名文件,并进行相同的读写操作阿

这个我想了一天了都没有想出来,

[解决办法]
lz应该是文件夹中还有子文件夹吧
遍历一下找出文件名相同的
vc代码供参考:

C/C++ code
    CString strPath;    CString strYourCaption(_T("Your caption here..."));    CString strYourTitle(_T("Your tilte here..."));        CPathDialog dlg(strYourCaption, strYourTitle, strPath);//新建对话框。        char drive[_MAX_DRIVE];    char dir[_MAX_DIR];    char fname[_MAX_FNAME];    char ext[_MAX_EXT];            if(dlg.DoModal()==IDOK)    {        strPath = dlg.GetPathName(); // this  is get file folder     }    else    {        return;    }    CFileFind  filefinder;    CStringList filelist; //文件列表    CStringList DirList;  //文件目录列表    CString PathStr;    CString CurPath;    CurPath=strPath +_T("\\*.*");            while(1)    {        int re;        if(filefinder.FindFile(LPCTSTR(CurPath)))        {               do             {                re=filefinder.FindNextFile();                if(filefinder.IsDots())//IsDots()表示上层目录,IsDirectory()表示本层,'.'和'..'。                    continue;                PathStr=filefinder.GetFilePath();//取得文件路径,包括扩展名。                if(filefinder.IsDirectory())//判断filefinder所指的对象是不是一个文件夹。                {                                           DirList.AddTail(PathStr);//保存文件目录名。                }                else                {                    CString str=filefinder.GetFileName();//取得文件名及其扩展名。                    _splitpath(PathStr,drive,dir,fname,ext);                    CString str1 = ext;//取扩展名。                    CString str3 = fname;                    str1.MakeLower();//变为小写。                    if ( str1 == ".jpg")                    {                        filelist.AddTail(PathStr);//保存文件及其扩展名。                        TRACE(PathStr+"\n");                    }                }            }            while(re);        }        if(DirList.IsEmpty())        {            break;        }        else         {                       CString tempStr = DirList.RemoveHead();            CurPath=tempStr + _T("\\*.*");        }    }
[解决办法]
用<io.h>
里面有个结构_finddata_t
struct _finddata_t {
unsigned attrib;
time_t time_create; /* -1 for FAT file systems */
time_t time_access; /* -1 for FAT file systems */
time_t time_write;
_fsize_t size;
char name[260];
};

方法有
_findfirst
_findnext
_findclose
[解决办法]
果然也发了, 呵呵。

热点排行