Pnig0s p.s. In fact, the main thing is to practice the memory ing file method. The Demo is a bit rough, and I used it to separate the SQL file myself.
The usage is clearly written in-h, and the size is calculated in KB. Pay attention to this when using it.
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1G0403b7-0.jpg "/> 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1G0403553-1.jpg "/>
- # Include <stdio. h>
- # Include <iostream>
- # Include <Windows. h>
- # Include <time. h>
- # Include "head. h"
- Using namespace std;
- Int main (int argc, char * argv []) {
- HANDLE hInFile = INVALID_HANDLE_VALUE; // remain
- HANDLE hInMap;
- FILEINFO fi;
- BOOL bHelp = FALSE;
- DWORD dwPartSize;
- For (int I = 0; I <argc; I ++ ){
- If (argc = 1 ){
- BHelp = TRUE;
- }
- LPSTR lpChkCmd = argv [I];
- LPSTR lpValue = argv [I + 1];
- If (lstrcmp (lpChkCmd, "-f") = 0 ){
- Fi. lpFileName = lpValue;
- } Else if (lstrcmp (lpChkCmd, "-s") = 0 ){
- DwPartSize = atol (lpValue) * 1024;
- } Else if (lstrcmp (lpChkCmd, "-h") = 0 ){
- BHelp = TRUE;
- }
- }
- If (bHelp ){
- Printf ("\ n --------------------------------");
- Printf ("\ n | \ tLarge file dividing \ t | ");
- Printf ("\ n | \ t \ tby: Pnig0s1992 \ t | ");
- Printf ("\ n | \ t \ t2011, 11,25 \ t | ");
- Printf ("\ n --------------------------------");
- Printf ("\ nUsage: \ n"
- & Quot; % s-f div.txt-s 1024 \ n & quot"
- "Options: \ n"
- "-F Specify the file u want to divide. \ n"
- "-S Specify the size for each part (KB). \ n"
- "-H Display the usage. \ n", argv [0]);
- Exit (1 );
- }
- HInFile = CreateFile (fi. lpFileName, GENERIC_READ | GENERIC_WRITE, file_pai_read | file_write _write, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
- If (hInFile = INVALID_HANDLE_VALUE ){
- Printf ("\ n failed to open the file (% d).", GetLastError ());
- Return 0;
- }
- Fi. dwFileLowSize = GetFileSize (hInFile, & fi. dwFileHighSize );
- Fi. dwFileSize = fi. dwFileLowSize;
- HInMap = CreateFileMapping (hInFile, NULL, PAGE_READWRITE, 0, 0, NULL );
- If (hInMap = NULL ){
- Printf ("\ n failed to create source file ing (% d).", GetLastError ());
- CloseHandle (hInFile );
- Return 0;
- }
- Fi. dwPartNum = fi. dwFileSize/dwPartSize;
- If (fi. dwFileSize % dwPartSize )! = 0 ){
- Fi. dwPartNum + = 1;
- }
- Printf ("\ n file size: % uKB \ t number of parts: % u \ n", fi. dwFileSize/1024, fi. dwPartNum );
- DWORD dwCurAddr = 0;
- DWORD dwCurSize = 0;
- System ("pause ");
- DWORD dwBegin, dwFinish;
- DwBegin = GetTickCount ();
- For (int index = 0; index <fi. dwPartNum; index ++ ){
- DwCurSize = fi. dwFileSize-dwCurAddr;
- If (dwCurSize> dwPartSize ){
- DwCurSize = dwPartSize;
- }
- LPVOID lpInMapContext;
- LpInMapContext = MapViewOfFile (hInMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, dwCurAddr, dwCurSize );
- If (! LpInMapContext ){
- Printf ("\ n failed to create the source file view. (% d)", GetLastError ());
- CloseHandle (hInFile );
- Return 0;
- }
- DwCurAddr + = dwCurSize;
- Char cIndex [4];
- Itoa (index + 1, cIndex, 10 );
- HANDLE hOutFile;
- HOutFile = CreateFile (cIndex, GENERIC_ALL, file_pai_read | file_pai_write, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
- If (hOutFile = INVALID_HANDLE_VALUE ){
- Printf ("\ n failed to create the target file (% d).", GetLastError ());
- Return 0;
- }
- HANDLE hOutMap;
- HOutMap = CreateFileMapping (hOutFile, NULL, PAGE_READWRITE, 0, dwCurSize, NULL );
- If (hOutMap = NULL ){
- Printf ("\ n failed to create the target file ing (% d).", GetLastError ());
- Return 0;
- }
- LPVOID lpOutMapContext;
- LpOutMapContext = MapViewOfFile (hOutMap, FILE_MAP_WRITE, 0, 0 );
- If (hOutMap = NULL ){
- Printf ("\ n failed to create the target file view. (% d)", GetLastError ());
- Return 0;
- }
- CopyMemory (lpOutMapContext, lpInMapContext, dwCurSize );
- Printf ("\ n [MSG] block % d completed.", index + 1 );
- UnmapViewOfFile (lpInMapContext );
- UnmapViewOfFile (lpOutMapContext );
- CloseHandle (hOutMap );
- CloseHandle (hOutFile );
- }
- CloseHandle (hInMap );
- CloseHandle (hInFile );
- DwFinish = GetTickCount ();
- DWORD dwRunTime = dwFinish-dwBegin;
- Printf ("\ n time: % u millisecond", dwRunTime );
- Return 1;
- }
This article is from the "About: Blank H4cking" blog, please be sure to keep this source http://pnig0s1992.blog.51cto.com/393390/724509