C++ 文件怎么就写不进去 WriteFile() 高手指点一二,谢谢
#include "stdafx.h"
#include <vector>
#include <Windows.h>
#include <stdio.h>
using namespace std;
int parFile( LPCTSTR pPath )
{
CFileFind finder;
CTime tempTime;
DWORD dwBytesRead, dwBytesWritten;
// 创建txt文件并把信息写入
HANDLE hFile = CreateFile( _T("c:\\MyText.txt"),
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL|
FILE_FLAG_OVERLAPPED,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("Could not open file(error %d)!", GetLastError());
return 0;
}
// Start work for file.
CString str;
CString cTime;
CString Path;
int sLength;
char* buf = NULL;
BOOL bWorking = finder.FindFile(pPath);
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
{
continue;
}
if (finder.IsDirectory())
{
str = finder.GetFileName();
sLength = finder.GetLength();
if (finder.GetCreationTime(tempTime))
{
cTime = tempTime.Format(_T("%c"));
}
Path = finder.GetFilePath();
}
WriteFile(_T("c:\\MyText.txt"),str,sizeof(str),0,NULL);
}
finder.Close();
return 0;
}
这是一个函数,我要读一个路径下的所有文件名字,创建时间然后写入一个文档,为什么写不进去,麻烦高手指点一二,或者给个完整的程序在2005下跑。