LaNiZ Posted January 6, 2010 Share Posted January 6, 2010 Hello everyone! I've been trying to make a File Splitter for the last couple of hours but it doesn't seem to work very well! Everything works fine. It reads the selected file (in this case an .exe file) and splits it into 4 new files (So called .Part files). The problem is that the part files is not as big as the .exe should be and then i try to merge them together again (with my own File Merger) windows thinks it's a kind of CMD File and the file wouldn't work at all! Here's the code for the File Splitter: Dim $File = FileOpenDialog("Select File", "C:\","All Files (*.*)", 1 + 2) FileCopy($File, $File & ".TEMPCopy", 0) Dim $FileOpened = FileOpen($File & ".TEMPCopy", 0) if $FileOpened = -1 Then msgbox(0,"", "There was an error with the file!") Else Dim $FileString = FileRead($File) Dim $StringLen = StringLen($FileString) Dim $Count = $StringLen / 4 Dim $String1 = StringLeft($FileString, $Count) StringTrimLeft($FileString, $Count) Dim $String2 = StringLeft($FileString, $Count) StringTrimLeft($FileString, $Count) Dim $String3 = StringLeft($FileString, $Count) StringTrimLeft($FileString, $Count) Dim $String4 = $FileString $Path = FileSelectFolder("Select Folder to place Files In", "C:\") Dim $File1 = FileOpen($Path & "\Part1.TFile", 2) FileWrite($File1, $String1) FileClose($File1) Dim $File2 = FileOpen($Path & "\Part2.TFile", 2) FileWrite($File2,$String2) FileClose($File2) Dim $File3 = FileOpen($Path & "\Part3.TFile", 2) FileWrite($File3,$String3) FileClose($File3) Dim $File4 = FileOpen($Path & "\Part4.TFile", 2) FileWrite($File4,$String4) FileClose($File4) FileClose($FileOpened) EndIf And here's the code for the File Merger: $Path = FileSelectFolder("Select Folder Where to Part Files are in", "C:\") Dim $File1 = FileOpen($Path & "\Part1.TFile", 0) Dim $String1 = FileRead($File1) FileClose($File1) Dim $File2 = FileOpen($Path & "\Part2.TFile", 0) Dim $String2 = FileRead($File2) FileClose($File2) Dim $File3 = FileOpen($Path & "\Part3.TFile", 0) Dim $String3 = FileRead($File3) FileClose($File3) Dim $File4 = FileOpen($Path & "\Part4.TFile", 0) Dim $String4 = FileRead($File4) FileClose($File4) $CompleteString = $String1 & $String2 & $String3 & $String4 if( FileExists($Path & "\File.exe") = 1 ) Then $Filename = "\File_2.exe" Else $Filename = "\File.exe" EndIf $Exe = FileOpen($Path & $Filename, 2) FileWrite($Exe , $CompleteString) FileClose($Exe) Link to comment Share on other sites More sharing options...
JohnOne Posted January 6, 2010 Share Posted January 6, 2010 Without knowing even if this method would work, Bear this in mind. What if $Count = $StringLen / 4 is not an integer ? would it cause a problem ? AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 6, 2010 Share Posted January 6, 2010 You need to use binary mode .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
LaNiZ Posted January 6, 2010 Author Share Posted January 6, 2010 (edited) You need to use binary mode Actually, i already tried using Binary mode ( + 16 ) with all the FileOpen() Calls.. No luck there, it only made it worse..Without knowing even if this method would work, Bear this in mind.What if $Count = $StringLen / 4 is not an integer ? would it cause a problem ?I've thought of that too, but i don't know what else i could do..The file I'm trying to split has the size of 23 kb and if i try Binary mode each of my .Part files ends up on 12 Bytes. and that's WAY to little.. Edited January 6, 2010 by LaNiZ Link to comment Share on other sites More sharing options...
AndyG Posted January 6, 2010 Share Posted January 6, 2010 Hi, i changed your code to split the file a little bit so it works now. Comments included expandcollapse popup#include <File.au3> local $drive,$dir,$name,$ext Dim $File = FileOpenDialog("Select File", "C:\","All Files (*.*)", 1 + 2) $split=_pathsplit($file,$drive,$dir,$name,$ext) ;i dont know if there is a problem with files with more then one dot (.) in the filename, so i changed FileCopy($File,@tempdir&"\"& $name & ".TEMPCopy", 0) ;tempdir is a nice place to store temporaray files Dim $FileOpened = FileOpen(@tempdir&"\"& $name & ".TEMPCopy", 0) if $FileOpened = -1 Then msgbox(0,"", "There was an error with the file!") Else Dim $FileString = FileRead($File) Dim $StringLen = StringLen($FileString) Dim $Count = int($StringLen / 4)+1 Dim $String1 = StringLeft($FileString, $Count) $filestring=StringTrimLeft($FileString, $Count) ;stringtrimleft is nice, but nothing happens if you dont assign it to a variable Dim $String2 = StringLeft($FileString, $Count) $filestring=StringTrimLeft($FileString, $Count) Dim $String3 = StringLeft($FileString, $Count) Dim $String4 = StringTrimLeft($FileString, $Count) $Path = FileSelectFolder("Select Folder to place Files In", "C:\") Dim $File1 = FileOpen($Path & "\"&$name&"_Part1.TFile", 18) ;16 for binary, 2 to overwrite existing files FileWrite($File1, $String1) FileClose($File1) Dim $File2 = FileOpen($Path & "\"&$name&"_Part2.TFile", 18) FileWrite($File2,$String2) FileClose($File2) Dim $File3 = FileOpen($Path & "\"&$name&"_Part3.TFile", 18) FileWrite($File3,$String3) FileClose($File3) Dim $File4 = FileOpen($Path & "\"&$name&"_Part4.TFile", 18) FileWrite($File4,$String4) FileClose($File4) FileClose($FileOpened) filedelete(@tempdir&"\"& $name & ".TEMPCopy") ;delete temporary file EndIf Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now