1.查询处理文件夹下的文件名称:
long handle;
CString srt;
struct _finddata_t FileInfo;
const char *to_search = "C:\\Users\\FuLiang-Yin\\Desktop\\www\\*.txt";
handle = _findfirst(to_search, &FileInfo);
int y = 0;
if (-1 == handle)
{
MessageBox(L"没有找到匹配的项目\n");
}
else
{
srt = FileInfo.name;
data1.push_back(srt);
while (!_findnext(handle, &FileInfo))
{
srt = FileInfo.name;
data1.push_back(srt);
y++;
}
for (int i=0;i<=y;i++)
{
DeleteFile(_T("C:\\Users\\FuLiang-Yin\\Desktop\\www\\") + data1[i]);
}
_findclose(handle);
data.push_back(y+1);
srt.Format(_T("%d"), data[0]);
y = 0;
SetDlgItemText(IDC_SNUM, srt);
MessageBox(L"已经处理完成"+ srt+"数据!");
}
2.移动或者删除文件
CStdioFile file;
CString Sat;
BOOL B_bool = 1;
for (int i=0;i<=3;i++)
{
file.Open(_T("C:\\Users\\FuLiang-Yin\\Desktop\\异常数据\\" + data1[i] + ".csv"), CFile::modeRead);
CString str;
int io = 0;
int num = 0;
CString substr[77];
while (file.ReadString(str))
{
str = str.Trim(_T(" "));
int count = 0;
int index = str.Find(_T(","));
while (index != -1 && count < 71)
{
substr[count++] = str.Left(index);
str = str.Right(str.GetLength() - index - 1);
index = str.Find(_T(","));
}
substr[count++] = str;
Index = m_list1.InsertItem(0xffff, _T(""));
int u = 59;
for (int i = 0; i <= DT; i++)
{
m_list1.SetItemText(Index, i, substr[u]);
u++;
}
if (substr[65] == " --------"|| substr[66]=="---- "|| substr[67] == " --------" || substr[68] == "---- "|| substr[69] == " --------" || substr[70] == "---- ")
{
num++;
}
io++;
}
CString str11, str12;
str11.Format(_T("%d"), io);
str12.Format(_T("%d"), num);
SetDlgItemText(IDC_STATIC1, str11);
SetDlgItemText(IDC_STATIC2, str12);
file.Close();
if (num>10)
{
BOOL bMoveOK = MoveFile(_T("C:\\Users\\FuLiang-Yin\\Desktop\\异常数据\\" + Sat + ".csv"), _T("C:\\Users\\FuLiang-Yin\\Desktop\\异常数据1\\" + Sat + ".csv"));
if (bMoveOK)
MessageBox(_T("移动成功!"), _T("Tip"), MB_OK);
else
MessageBox(_T("移动失败!"), _T("Tip"), MB_OK);
}
io = 0;
num = 0;
}