1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| VOID TestFile(){ HANDLE hFile = CreateFile( "C:\\A.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
CloseHandle(hFile);
DWORD dwHigh = 0; DWORD dwLow = GetFileSize(hFile, &dwHigh);
WIN32_FILE_ATTRIBUTE_DATA data = {0}; GetFileAttributesEx("z:\\hello",GetFileExInfoStandard,&data); printf("Attri=%lx\n",data.dwFileAttributes); printf("SizeHigh=%lx\n",data.nFileSizeHigh); printf("SizeLow=%lx\n",data.nFileSizeLow); printf("CreationTime=%lx\n",data.ftCreationTime); printf("LastAccessTime=%lx\n",data.ftLastAccessTime); printf("LastWriteTime=%lx\n",data.ftLastWriteTime);
LPSTR pszBuffer = (LPSTR)malloc(10); ZeroMemory(pszBuffer,10); SetFilePointer(hFile, 1, NULL, FILE_END); DWORD dwReadLength = 0; ReadFile(hFile, pszBuffer, 10, &dwReadLength, NULL); printf("%s",pszBuffer); free(pszBuffer); CloseHandle(hFile);
TCHAR szBuffer[] = TEXT("中国"); DWORD dwWritten = 0; WriteFile(hFile, szBuffer, strlen(szBuffer),&dwWritten, NULL); CloseHandle(hFile); CopyFile("Z:\\old.txt","z:\\new.txt",FALSE); DeleteFile("z:\\old.txt"); }
|