16,473
社区成员
发帖
与我相关
我的任务
分享
CString lname,sname;
CString path = _T("");
CString temp = _T("");
path = GetPath();
int count = m_list.GetItemCount(); //获得列表项目数
for(int i = 0; i < count; i++ )
{
lname = m_list.GetItemText(i,0); //循环读取每个文件
CFile file1,file2;
if (file1.Open(lname,CFile::modeRead) && (path != _T(""))) //判断如果打开成功并且存储路径存在则..
{
temp = path;
sname = GetFileTitleFromFileName(lname,TRUE); //获取文件全名
path += sname;
uLong slength;
slength = compressBound (file1.GetLength()); //判断加密后文件大小
file2.Open(path,CFile::modeCreate|CFile::modeWrite); //打开创建加密后的文件
Bytef *source = new Bytef [file1.GetLength()]; //new
Bytef *dest = new Bytef [slength]; //NEW
while (file1.Read(source,_msize(source))) //循环读取每个需要加密的文件
{
compress(dest,&slength,source,file1.GetLength()); //ZLIB加密函数
file2.Write(dest,slength); //写文件
}
delete [] source;
delete [] dest;
file1.Close();
file2.Close();
path.Empty( ); //清空路径
path = temp;
}
}