Nikolle9203 Posted February 8, 2014 Posted February 8, 2014 (edited) Guys could you help me to convert this python script to autoit ? I cant understand some of the python reference operator therefore i cant write it to autoit : /. expandcollapse popupfn=raw_input("File: ")f=open(fn,"rb") data=f.read() f.close() bat1="" byte=700 batlen=220 i=0 c=1 while i+byte<len(data): fn2="parts/"+fn+"_part"+str(c) data2=data[i:i+byte] f=open(fn2,"wb") f.write(data2) f.close() i+=byte c+=1 fn2="parts/"+fn+"_part"+str(c) data2=data[i:] f=open(fn2,"wb") f.write(data2) f.close() a=True b=1 c+=1 while a: i=c-batlen if i<=1: i=1 a=False bat2="COPY /B " while i<c: fn2="\""+fn+"_part"+str(i)+"\"" bat2+=fn2+" + " i+=1 bat2=bat2[0:-3] batname=str( +".bat" bat1+=bat2+"\r\n" b+=1 c-=batlen-1 f=open("parts/compile.bat","w") f.write(bat1) f.close() This is the python script.Basically what it does is to read the file , split it to sub files with names like part_1 , part_2 and then writes a .bat to assembly it again. $iPartSize = 256 $sPath = "test.exe" $bat2="COPY /B " $hFile = FileOpen($sPath,16) $sRead = FileRead($hFile) FileClose($hFile) $iTotalLenght = BinaryLen($sRead) $iPartCount = $iTotalLenght/$iPartSize $sPathSplit = StringSplit($sPath,"") DirCreate($sPath&".part") For $i = 1 to Ceiling($iPartCount) $hPartFile = FileOpen($sPath&".part"&$sPathSplit[$sPathSplit[0]]&"."&$i&".part",16+2) FileWrite($hPartFile, BinaryMid($sRead,($i-1)*$iPartSize+1,$iPartSize)) $batch=@ScriptDir&"comp.bat" FileWrite($batch,$bat2&$hPartFile) FileClose($hPartFile) Next So far im done with the file splitter but i cant manage to create the .bat :/ Thanks Edited February 8, 2014 by Nikolle9203
Nikolle9203 Posted February 9, 2014 Author Posted February 9, 2014 Ok so im almost done.I did the hard part but now im unable to fully complete it.Its working fine if the file is less than 100KB.But i need to make it now to write to new line if $i < 200.I can do that manualy but what if the file size is bigger than the varaibles i put in. expandcollapse popup$iPartSize = 512 $sPath = @scriptdir&"\test.exe" If @error Then Exit ;;;;;;$getsize = FileGetsize($spath) ;;;;;;$partnumber = $getsize/$ipartsize ;;;;;;msgbox(0,'',$partnumber) $hFile = FileOpen($sPath,16) $sRead = FileRead($hFile) FileClose($hFile) $exename = StringTrimLeft($sPath, StringInStr($sPath, "\", 2, -1)) $iTotalLenght = BinaryLen($sRead) $iPartCount = $iTotalLenght/$iPartSize $sPathSplit = StringSplit($sPath,"\") DirCreate($sPath&".part") global $caca= "COPY /B " global $dada= "" For $i = 1 to Ceiling($iPartCount) $hPartFile = FileOpen($sPath&".part\"&$sPathSplit[$sPathSplit[0]]&"."&$i&".part",16+2) FileWrite($hPartFile, BinaryMid($sRead,($i-1)*$iPartSize+1,$iPartSize)) FileClose($hPartFile) if $i < 210 then $caca &= '"'&$exename&'.'&$i&'.part"'&' + ' else $dada &= '"'&$exename&'.'&$i&'.part"'&' + ' endif Next $batch=@ScriptDir&"\comp.bat" $cacato=stringTrimRight($caca,2) $dadato=stringtrimright($dada,2) FileWrite($batch,$cacato&@CRLF) $splitter1 = StringTrimLeft($cacato, StringInStr($cacato, "+", 2, -1)) FileWrite($batch,"COPY /b "&$splitter1&" + "&$dadato) The output of comp.bat will be -http://pastebin.com/C3nc2NeC $LAST PART = in this case is "test.exe.209.part" All i want is when exceed 200 to write to a new line starting with "COPY /B " & $LAST PART + ........
Danp2 Posted February 9, 2014 Posted February 9, 2014 What exactly isn't working properly? The only issue I can see is that the last FileWrite should only occur if $iPartCount > 210, so you need to check for that. Also, what happens if $iPartCount > 420, etc? Latest Webdriver UDF Release Webdriver Wiki FAQs
Nikolle9203 Posted February 9, 2014 Author Posted February 9, 2014 If $iPartCount > 420 the compile.bat wouldnt compile it properly since CMD doesnt support that long line.The idea is to keep the lines bellow 220 parts.Also the last line is just and example.It will work if the "test.exe" is bellow 100KB.But i want to make it work and with bigger files. All i want to is compile.bat to be with this output: COPY /B "PART1" + "PART2" + ..................................... + "PART200" COPY /B "PART200" + "PART201" + .............................. + "PART400" COPY /B "PART400" + "PART401" + ............................. and so on.
Danp2 Posted February 9, 2014 Posted February 9, 2014 Untested, but you might try something like this: $iPartSize = 512 $sPath = @scriptdir&"\test.exe" $hFile = FileOpen($sPath,16) $sRead = FileRead($hFile) FileClose($hFile) $exename = StringTrimLeft($sPath, StringInStr($sPath, "\", 2, -1)) $iTotalLenght = BinaryLen($sRead) $iPartCount = $iTotalLenght/$iPartSize $sPathSplit = StringSplit($sPath,"\") DirCreate($sPath&".part") Local $caca= "COPY /B " Local $dada= "" Local $max = Ceiling($iPartCount) Local $batch=@ScriptDir&"\comp.bat" For $i = 1 to $max $hPartFile = FileOpen($sPath&".part\"&$sPathSplit[$sPathSplit[0]]&"."&$i&".part",16+2) FileWrite($hPartFile, BinaryMid($sRead,($i-1)*$iPartSize+1,$iPartSize)) FileClose($hPartFile) $dada &= '"'&$exename&'.'&$i&'.part"'&' + ' If Mod($i, 200) Or $i = $max Then $dadato=stringtrimright($dada,2) FileWrite($batch,$caca & $dadato&@CRLF) $dada = '"'&$exename&'.'&$i&'.part"'&' + ' EndIf Next Latest Webdriver UDF Release Webdriver Wiki FAQs
Nikolle9203 Posted February 9, 2014 Author Posted February 9, 2014 Nope doesnt work.But THANK U ill try to fix it , i think im able to fix it now .
Danp2 Posted February 9, 2014 Posted February 9, 2014 Looks like I forgot to check the result of the Mod function. Try changing that line to: If Mod($i, 200)=0 Or $i = $max Then Latest Webdriver UDF Release Webdriver Wiki FAQs
Nikolle9203 Posted February 9, 2014 Author Posted February 9, 2014 (edited) Looks like I forgot to check the result of the Mod function. Try changing that line to: If Mod($i, 200)=0 Or $i = $max Then Still doesnt work but we are almost done ! . Now the results are : test.exe.1.part is 100 KB , test.exe.200.part is 101 KB , test.exe.400.part is 101 KB and so on until test.exe.1000.part. Somewhere the chain is lost . The compiler have to combine all parts to test.exe.1.part so test.exe.1.part will be 635 KB. The output compile.bat is : http://pastebin.com/xaP23VyK. Exactly what i wanted from compile.bat Once again Thank you Edited February 9, 2014 by Nikolle9203
Danp2 Posted February 9, 2014 Posted February 9, 2014 Given the code you have posted, I'm not sure why the first file would be smaller than the others. One issue I do see is that you are including the "border" file twice when you split the copy command. I wrote it that way because that's what you indicated you needed. However, this doesn't seem correct if you are trying to reassemble the parts into a single file. If that's the case, you would want to change: $dada = '"'&$exename&'.'&$i&'.part"'&' + ' to: $dada = "" Latest Webdriver UDF Release Webdriver Wiki FAQs
Nikolle9203 Posted February 9, 2014 Author Posted February 9, 2014 Given the code you have posted, I'm not sure why the first file would be smaller than the others. One issue I do see is that you are including the "border" file twice when you split the copy command. I wrote it that way because that's what you indicated you needed. However, this doesn't seem correct if you are trying to reassemble the parts into a single file. If that's the case, you would want to change: $dada = '"'&$exename&'.'&$i&'.part"'&' + ' to: $dada = "" Nope thats not he problem.The problem is Compile.bat doesnt start the new line with previus part name. IE: COPY /B "test.exe.1.part" + "test.exe.2.part" + "test.exe.3.part" + "test.exe.4.part" + "test.exe.5.part" + "test.exe.6.part" COPY /B "test.exe.7.part" + "test.exe.8.part" + "test.exe.9.part" + "test.exe.10.part" It should be : COPY /B "test.exe.1.part" + "test.exe.2.part" + "test.exe.3.part" + "test.exe.4.part" + "test.exe.5.part" + "test.exe.6.part" COPY /B "test.exe.6.part" + "test.exe.7.part" + "test.exe.8.part" + "test.exe.9.part" + "test.exe.10.part"
Nikolle9203 Posted February 9, 2014 Author Posted February 9, 2014 Problem is solved.The problem was that Given the code you have posted, I'm not sure why the first file would be smaller than the others. One issue I do see is that you are including the "border" file twice when you split the copy command. I wrote it that way because that's what you indicated you needed. However, this doesn't seem correct if you are trying to reassemble the parts into a single file. If that's the case, you would want to change: $dada = '"'&$exename&'.'&$i&'.part"'&' + ' to: $dada = "" $dada = "" no need to change it. The problem was that compile.bat has to write backwards in roder : COPY /B "test.exe.6.part" + "test.exe.7.part" + "test.exe.8.part" + "test.exe.9.part" + "test.exe.10.part" COPY /B "test.exe.1.part" + "test.exe.2.part" + "test.exe.3.part" + "test.exe.4.part" + "test.exe.5.part" + "test.exe.6.part" the wrong one was : COPY /B "test.exe.1.part" + "test.exe.2.part" + "test.exe.3.part" + "test.exe.4.part" + "test.exe.5.part" + "test.exe.6.part" COPY /B "test.exe.6.part" + "test.exe.7.part" + "test.exe.8.part" + "test.exe.9.part" + "test.exe.10.part" Thanks again for the support
Nikolle9203 Posted February 9, 2014 Author Posted February 9, 2014 EDIT : How can i make it to write every new data to the first line ? I tried _FileWriteToLine ($batch,1,@CRLF&$caca & $dadato&@CRLF) but doesnt work :/.
Danp2 Posted February 9, 2014 Posted February 9, 2014 (edited) Problem is solved.The problem was that $dada = "" no need to change it. The problem was that compile.bat has to write backwards in roder : COPY /B "test.exe.6.part" + "test.exe.7.part" + "test.exe.8.part" + "test.exe.9.part" + "test.exe.10.part" COPY /B "test.exe.1.part" + "test.exe.2.part" + "test.exe.3.part" + "test.exe.4.part" + "test.exe.5.part" + "test.exe.6.part" the wrong one was : COPY /B "test.exe.1.part" + "test.exe.2.part" + "test.exe.3.part" + "test.exe.4.part" + "test.exe.5.part" + "test.exe.6.part" COPY /B "test.exe.6.part" + "test.exe.7.part" + "test.exe.8.part" + "test.exe.9.part" + "test.exe.10.part" Thanks again for the support OIC. It would probably be best to supply a destination filename. That way the original .part file will remain unchanged EDIT : How can i make it to write every new data to the first line ? I tried _FileWriteToLine ($batch,1,@CRLF&$caca & $dadato&@CRLF) but doesnt work :/. Again, I think this will work if you used a destination filename. Again, not tested, but try this: For $i = 1 to $max $hPartFile = FileOpen($sPath&".part\"&$sPathSplit[$sPathSplit[0]]&"."&$i&".part",16+2) FileWrite($hPartFile, BinaryMid($sRead,($i-1)*$iPartSize+1,$iPartSize)) FileClose($hPartFile) $dada &= '"'&$exename&'.'&$i&'.part"'&' + ' If Mod($i, 200)=0 Or $i = $max Then $dadato=stringtrimright($dada,1) FileWrite($batch,$caca & $dadato & $exename &@CRLF) $dada = '' EndIf Next Edit: Just thinking about this, the code would need to be modified so that the 2nd and subsequent copy commands would include the EXE file as the first part of the command, so you would actually want: $dada = $exename & ' ' Edited February 9, 2014 by Danp2 Latest Webdriver UDF Release Webdriver Wiki FAQs
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