我做了个视频管理平台.现在想用一个文本文件来存储本地视频文件的名字,可以在此平台上方便的查找,添加视频文件到这个管理平台的一个列表中.我借鉴了一个代码,但是始终不能将文件添加进我的管理平台,不知道哪里错了.希望指点.
void localmanage::Onaddlocal()
{
// TODO: Add your control notification handler code here
CFileDialog *SaveDlg;
CString inname;
CString toname;
char localbuff[MAX_PATH];
SaveDlg = new CFileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_EXPLORER, _T("avi Files (*.avi)|*.avi||"), NULL);
if(SaveDlg->DoModal() == IDOK)
{
inname = SaveDlg->GetPathName();
CopyFile(localbuff,toname ,FALSE);
delete SaveDlg;
}
else
{
delete SaveDlg;
return;
}
FILE *flocalman;
int num=0;
char fname[_MAX_FNAME];
memset(fname,0,_MAX_FNAME);
char fnamenew[_MAX_FNAME];
memset(fnamenew,0,_MAX_FNAME);
CString fname2;
CString fnamenew2;
CString tempmsg;
int tag=0;
tempmsg.Format(_T("%s%s%s"),g_Config.szWorkDir,"\\","record.txt") ;
_splitpath(inname,NULL,NULL,fnamenew,NULL) ;
fnamenew2=fnamenew;
if ((flocalman=fopen(tempmsg,"r"))!=NULL)
{
CString localbuff;
fseek(flocalman, 0, SEEK_SET) ;
// static int tempnum=0;
while(!feof(flocalman))
{
memset(fname,0,_MAX_FNAME);
fseek(flocalman, num, SEEK_SET) ;
fscanf(flocalman,"%[^\n]",localbuff);
_splitpath(localbuff,NULL,NULL,fname,NULL) ;
fname2=fname;
if (fnamenew2==fname2)
{
tag=1;
CString warningexist;
warningexist.Format(_T("%s已存在,请改名后添加"),inname);
MessageBox(warningexist,_T("提醒"),MB_ICONWARNING);
break;
}
num=strlen(localbuff)+num+1;
}
if (tag==0)
{
if (flocalman)
{
fclose(flocalman);
flocalman=NULL;
}
int fh=_open(inname,_O_RDONLY);
if (fh!=(-1))
{
if (_filelength(fh)>=10000)
{
flocalman= fopen(tempmsg,"ab");
fwrite(inname,1,inname.GetLength(),flocalman);
fwrite("\n",1,1,flocalman);
}
else
{
MessageBox(_T("非法的AVI文件"),_T("提醒"),MB_ICONWARNING);
}
}
_close(fh);
}
}
if (flocalman)
{
fclose(flocalman);
flocalman=NULL;
}
refreshlist();
((local *)g_Config.localdlg)->refreshlist();
}