softairhk

softairhk

  • NA
  • 115
  • 0

File Splitter Problems

Oct 8 2003 2:10 AM
Hello! I have found a File Splitter coding from the website, but I found that it has a problem: The generated *.bat will be in this format e.g. demo.exe.bat Copy /B "F:\Temp\demo.exe.1"+"F:\Temp\demo.exe.2"+"F:\Temp\demo.exe.3" "F:\Temp\demo.exe" The problem is if I send the demo.exe.1, demo.exe.2, demo.exe.3 and demo.exe.bat to other user via FTP, then he must edit the demo.exe.bat again. So how to modify the following coding to change the generate demo.exe.bat to out as following: e.g. demo.exe.bat Copy /B "demo.exe.1"+"demo.exe.2"+"demo.exe.3" "demo.exe" //Open File private void Open() { OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter = "All Files (*.*)|*.*|Winzip Files (*.zip)|*.zip|Winrar Files (*.rar)|*.rar|ISO Files (*.iso)|*.iso|Execute Files (*.exe)|*.exe|Install Files (*.msi)|*.msi"; openDlg.FileName = "" ; openDlg.CheckFileExists = true; openDlg.CheckPathExists = true; DialogResult res = openDlg.ShowDialog (); if(res == DialogResult.OK) { if( openDlg.FileName=="") MessageBox.Show("Unexpected file format","Error File Name",MessageBoxButtons.OK,MessageBoxIcon.Information ); else { txtFileName.Text =openDlg.FileName; btnSplit.Enabled =true; FileStream fr = new FileStream(txtFileName.Text,FileMode.Open, FileAccess.Read ); FileSize =fr.Length; { intFileSize.Text =((Convert.ToInt32(fr.Length))/1024/1024).ToString()+ "."+(Convert.ToInt32(fr.Length)%(1024*1024))/1024+"M"; intPecFileSize.Text =((Convert.ToInt32(fr.Length/2.0))/1024/1024).ToString()+ "."+(Convert.ToInt32(fr.Length/2.0)%(1024*1024))/1024+"M"; //doubleFileSize.Text =((Convert.ToInt32(fr.Length))/1024/1024).ToString()+ "."+(Convert.ToInt32(fr.Length)%(1024*1024))/1024+"M"; //doublePecFileSize.Text =((Convert.ToInt32(fr.Length/2.0))/1024/1024).ToString()+ "."+(Convert.ToInt32(fr.Length/2.0)%(1024*1024))/1024+"M"; } fr.Close(); } } } //Split File private void btnSplit_Click(object sender, System.EventArgs e) { int i; string strLog=""; btnSplit.Enabled =false; btnBrowse.Enabled =false; progressBar1.Minimum =1; progressBar1.Maximum =Convert.ToInt32(numericUpDown1.Value)+1; progressBar1.Value =1; FileStream fread = new FileStream(txtFileName.Text,FileMode.Open, FileAccess.Read); int filesize = Convert.ToInt32(fread.Length) /Convert.ToInt32(numericUpDown1.Value); StreamWriter fwrite = new StreamWriter(txtFileName.Text +".bat",false); strLog="Copy /B "; for(i=1;i<=Convert.ToInt32(numericUpDown1.Value);i++) { byte[] byteread=new byte[filesize] ; fread.Read(byteread,0,filesize); FileStream fw = new FileStream( txtFileName.Text +"." + i ,FileMode.CreateNew, FileAccess.Write); strLog =strLog + "\""+txtFileName.Text+"."+Convert.ToString(i)+"\"+"; foreach(byte bNext in byteread) fw.WriteByte(bNext) ; fw.Close(); progressBar1.Value=i; } if( fread.Length!=fread.Position ) { byte [] byteread=new byte[Convert.ToInt32(fread.Length) - filesize *(i-1)] ; fread.Read(byteread,0,Convert.ToInt32(fread.Length) -filesize*(i-1)); FileStream fw = new FileStream( txtFileName.Text +"." +i ,FileMode.CreateNew, FileAccess.Write); strLog =strLog +"\""+txtFileName.Text+"."+Convert.ToString(i)+"\""; foreach(byte bNext in byteread) fw.WriteByte(bNext) ; fw.Close(); } else { strLog =strLog.Substring(0,strLog.Length -2); strLog =strLog +"\""; } strLog =strLog +" \""+txtFileName.Text+"\""; fwrite.Write(strLog); fread.Close(); fwrite.Flush(); fwrite.Close(); progressBar1.Value =i; btnSplit.Enabled =true; btnBrowse.Enabled =true; MessageBox.Show("File Splitted Successfully!\n\nSplitted into:"+Convert.ToInt32(i-1)+" pieces!\n\n"+"Please run *.bat to merge the files!","Finished",MessageBoxButtons.OK,MessageBoxIcon.Information); } fm Softair