Source code: windows files are separated and merged. source code files are separated.
#include <Windows.h>#include <vector>#include <string>using namespace std;
// Determine whether the file contains bool FileExistsW (const wstring & fn) {WIN32_FIND_DATAW fd; HANDLE hFile = FindFirstFileW (fn. c_str (), & fd); if (hFile! = INVALID_HANDLE_VALUE) {: FindClose (hFile); return true;} return false;} // determine whether the directory contains bool DirectoryExistsW (const wstring & fn) {// return PathFileExistsA (fn. c_str (); DWORD Code = GetFileAttributesW (fn. c_str (); return (Code! = INVALID_FILE_ATTRIBUTES) & (FILE_ATTRIBUTE_DIRECTORY & Code )! = 0);} // directory + backslash wstring IncludeTrailingPathDelimiterW (const wstring & path) {wstring s = path; if (s. empty () return s; if (s [s. length ()-1]! = L' \ ') return s + L "\"; else return s;} // get the path file name wstring ExtractFileNameW (const wstring & filestr) {if (filestr. empty () return L ""; for (int I = filestr. length ()-1; I> = 0; -- I) {if (filestr [I] = L '\') {return filestr. substr (I + 1) ;}} return L "" ;}std: wstring IntToStrW (const int I) {wchar_t buf [16] = {0 }; _ itow_s (I, buf, 10); return wstring (buf);} inline void IncPtr (void ** p, int I) {* p = (void *) (I Nt) * p + I);} // split the bool BreakFile (const wchar_t * fn, unsigned long block_size, const wchar_t * save_path) {if (! FileExistsW (fn) return false; if (! DirectoryExistsW (save_path) return false; if (block_size <1) return false; HANDLE hf = CreateFileW (fn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); if (INVALID_HANDLE_VALUE = hf) return false; int iblock = 1; wstring fblock = IncludeTrailingPathDelimiterW (save_path) + ExtractFileNameW (fn) + L ". part "+ IntToStrW (iblock); HANDLE hfw = CreateFileW (fblock. c_str (), GENERIC_READ | GEN ERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); if (INVALID_HANDLE_VALUE = hfw) {CloseHandle (hf); return false;} DWORD dwWrited = 0, dwWritedTemp = 0; DWORD dwToWrite = 0; DWORD dwRemain = 0; unsigned char buf [8192]; DWORD dwReaded = 0; int iseek = 0; void * p = NULL; while (true) {dwReaded = 0; if (FALSE = ReadFile (hf, buf, sizeof (buf), & dwReaded, NULL) break; if (0 = dwReaded) break; iseek = 0; p = (void *) buf; dwRemain = dwReaded; label_rewrite: if (dwWrited >=block_size) {: CloseHandle (hfw); ++ iblock; fblock = IncludeTrailingPathDelimiterW (save_path) + ExtractFileNameW (fn) + L ". part "+ IntToStrW (iblock); hfw = CreateFileW (fblock. c_str (), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); if (INVALID_HANDLE_VALUE = hfw) {CloseHandle (hf); return false ;} dwWrited = 0 ;} IncPtr (& p, iseek); dwToWrite = min (dwRemain, block_size-dwWrited); dwWritedTemp = 0; if (FALSE = WriteFile (hfw, p, dwToWrite, & dwWritedTemp, NULL) break; dwWrited + = dwWritedTemp; if (dwRemain> dwWritedTemp) dwRemain = dwRemain-dwWritedTemp; else dwRemain = 0; iseek = dwWritedTemp; if (dwRemain> 0) goto callback; dwReaded = 0 ;}:: CloseHandle (hfw);: CloseHandle (hf); return true ;}// merge the file bool C OmbineFiles (const vector <wstring> & files, const wstring & destfile) {if (FileExistsW (destfile) return false; if (files. empty () return false; HANDLE hf = CreateFileW (destfile. c_str (), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); if (INVALID_HANDLE_VALUE = hf) return false; HANDLE hfr = INVALID_HANDLE_VALUE; unsigned char buf [8192]; DWORD dwReaded = 0, dwToWrite = 0, dwWrited = 0, dwRemain = 0, dwWritedTemp = 0; LONGLONG dwFileSize = 0, dwDestSize = 0; LARGE_INTEGER li; void * p = NULL; int iseek = 0; for (size_t I = 0; I <files. size (); ++ I) {if (! FileExistsW (files [I]) continue; hfr = CreateFileW (files [I]. c_str (), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (INVALID_HANDLE_VALUE = hfr) continue; li. quadPart = 0; if (FALSE = GetFileSizeEx (hfr, & li) {CloseHandle (hf); return false;} dwDestSize + = li. quadPart;} li. quadPart = dwDestSize; if (FALSE = SetFilePointerEx (hf, li, NULL, FILE_BEGIN) {CloseHandle (hf); re Turn false;} if (FALSE = SetEndOfFile (hf) {CloseHandle (hf); return false;} CloseHandle (hf); hf = CreateFileW (destfile. c_str (), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (inflow = hf) {hf = 0; return false;} hfr = INVALID_HANDLE_VALUE; for (size_t I = 0; I <files. size (); ++ I) {if (! FileExistsW (files [I]) continue; if (INVALID_HANDLE_VALUE! = Hfr) CloseHandle (hfr); hfr = CreateFileW (files [I]. c_str (), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (INVALID_HANDLE_VALUE = hfr) continue; label_read: dwReaded = 0; if (FALSE = ReadFile (hfr, buf, sizeof (buf), & dwReaded, NULL) continue; if (dwReaded = 0) continue; iseek = 0; p = (void *) buf; dwRemain = dwReaded; label_rewrite: IncPtr (& p, iseek); dwToWrite = dwRemain; d WWritedTemp = 0; if (FALSE = WriteFile (hf, p, dwToWrite, & dwWritedTemp, NULL) continue; dwWrited + = dwWritedTemp; if (dwRemain> dwWritedTemp) dwRemain = dwWritedTemp; else dwRemain = 0; iseek = dwWritedTemp; if (dwRemain> 0) goto label_rewrite; goto label_read;} if (INVALID_HANDLE_VALUE! = Hfr) CloseHandle (hfr); CloseHandle (hf); return true ;}
What is the C ++ source code of the file splitting and merging tool?
Give you a Java
Public class FileCut
/* Cl_tl */
{
Private Shell;
Private Display display;
Private Text txtSourceFile;
Private Text txtNewFilePath;
Private Text txtFileSize;
Private Button btnChooseFile;
Private Button btnChoosePath;
Private Button btnCut;
Private Button btnUnionFiles;
Private Button btnUp;
Private Button btnDown;
Private Button btnClear;
Private Button btnClearAll;
Private Button btnUnion;
Private Table tblFileList;
Private File sourceFile = null;/* Source File */
Private File [] newFile = null;/* split the File */
Private int fileCount = 0;/* Number of files divided */
Private int fileSize = 0;/* Split file block size */
Private String strSourceFile = null;/* source file path and name */
Private String strNewFilePath = null;/* Split file storage path */
Public static void main (String [] args)
{
Display display = new Display ();
FileCut Item = new FileCut ();
Item. createShell ();
While (! Item. shell. isDisposed ())
{
If (! Display. readAndDispatch ())
Display. sleep ();
}
Display. dispose ();
}
/* Fn_hd
* Rem: create a form
* Aut:
* Log: 2005-11-24
*/
Private void createShell ()
/* Fn_tl */
{
Shell = new Shell (display, SWT. MIN );
Shell. setBounds (300,250,500,330 );
Shell. setText ("file splitting and merging ");
GridLayout shellLayout = new GridLayout ();
ShellLayout. numColumns = 3;
Shell. setLayout (shellLayout );
CreateWidgets ();
Shell. open ();
}
/** Fn_hd
* Rem: add controls in the form
* Per:
* Aut:
* Log:... the remaining full text>
Separation and merging of C language programming files source code and program diagram (Course Design)
The C language divides a file into two equal files.
# Include <stdio. h>
Int main ()
{
Int len = 0;
Int len2 = 0;
FILE * stream;
FILE * stream1;
FILE * stream2;
Char buf [50];
Char buf1 [50];
Char buf2 [50];
Char text [1024];
Printf ("input anfile path to open :");
Scanf ("% s", buf );
Stream = fopen (buf, "r + ");
Fseek (stream, 0, SEEK_END );
Len = ftell (stream );
Printf ("the file % s length is % d! \ N ", buf, len );
Len2 = len/2;
Printf ("intput 2 file name: \ n ");
Scanf ("% s", buf1, buf2 );
Fseek (stream, 0, SEEK_SET );
Stream1 = fopen (buf1, "w + ");
Stream2 = fopen (buf2, "w + ");
Fread (text, len2, 1, stream );
Fwrite (text, len2, 1, stream1 );
Fread (text, len-len2, 1, stream );
Fwrite (text, len-len2, 1, stream2 );
Fclose (stream );
Fclose (stream1 );
Fclose (stream2 );
Return 0;
}
File Merging
# Include <stdio. h>
Int main ()
{
Int len = 0;
Int len2 = 0;
FILE * stream;
FILE * stream1;
Char buf [50];
Char buf1 [50];
Char text [1024];
Printf ("input anfile path to open :");
Scanf ("% s", buf );
Stream = fopen (buf, "r + ");
Fseek (stream, 0, SEEK_END );
Printf ("intput another file name: \ n ");
Scanf ("% s", buf1 );
Stream1 = fopen (buf1, "r + ");
Fseek (stream1, 0, SEEK_END );
Len = ftell (stream1 );
Fseek (stream1, 0, SEEK_SET );
Fread (text, len, 1, stream1 );
Fwrite (text, len, 1, stream );
Fclose (strea... the remaining full text>