tobias7 Posted March 29, 2008 Share Posted March 29, 2008 Hi. I'm looking for a way to combine multiple files into one file. I would then separate the files at a later time. I want this operation to be compatible with both XP and Vista. Does anyone have any ideas? Thanks in advance. Link to comment Share on other sites More sharing options...
monoceres Posted March 29, 2008 Share Posted March 29, 2008 Here's a suggestion: $part1=FileOpen("file1.ext",16) $part2=FileOpen("file2.ext",16) $comb=FileOpen("combinedfiles.ext",17) $string=FileRead($part1) string=$string&FileRead($part2) FileWrite($comb,$string) Just remember to save the size of file1 somewhere so you now where to split them up Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
jpam Posted March 29, 2008 Share Posted March 29, 2008 i made one , but its not finish yethttp://www.autoitscript.com/forum/index.php?showtopic=67444 Link to comment Share on other sites More sharing options...
tobias7 Posted March 29, 2008 Author Share Posted March 29, 2008 Here's a suggestion: $part1=FileOpen("file1.ext",16) $part2=FileOpen("file2.ext",16) $comb=FileOpen("combinedfiles.ext",17) $string=FileRead($part1) string=$string&FileRead($part2) FileWrite($comb,$string) Just remember to save the size of file1 somewhere so you now where to split them up Thanks a lot! That oughta help. Link to comment Share on other sites More sharing options...
Siao Posted March 29, 2008 Share Posted March 29, 2008 Just use an archiver, such as 7zip. If you don't care for compression and want speed, use TAR format. "be smart, drink your wine" Link to comment Share on other sites More sharing options...
tobias7 Posted March 30, 2008 Author Share Posted March 30, 2008 Just use an archiver, such as 7zip. If you don't care for compression and want speed, use TAR format.The problem with that is that I need my program to work on any normal Window XP or Vista computer. I'm trying to avoid having the people who use my program to install any other programs. Thanks for the idea though. Link to comment Share on other sites More sharing options...
tobias7 Posted March 30, 2008 Author Share Posted March 30, 2008 Thanks so much monoceres! Thanks to your suggestion, I was able to make exactly what I was looking for. Here is my latest library! I'm thinking I might even submit it to the official AutoIt library area after I make it look nice. expandcollapse popup#cs public functions $success = CMB_CombineFiles($unifileName, $separateFiles) CMB_ExtractFiles($unifileName, $separateFiles) $numberOfFiles = CMB_GetNumOfFiles($unifileName) #ce #cs private functions $tempString = CMB_P_GetNext($file) #ce #cs example Global $unifiletest = "C:\\Documents and Settings\\Tobias\\Desktop\\AutoITCombineTest\\somebodysetusupthebomb.zig" Global $separateFilestest[6] $separateFilestest[0] = "C:\\Documents and Settings\\Tobias\\Desktop\\AutoITCombineTest\\file1.txt" $separateFilestest[1] = "C:\\Documents and Settings\\Tobias\\Desktop\\AutoITCombineTest\\file2.mid" $separateFilestest[2] = "C:\\Documents and Settings\\Tobias\\Desktop\\AutoITCombineTest\\file3.jpg" $separateFilestest[3] = "C:\\Documents and Settings\\Tobias\\Desktop\\AutoITCombineTest\\file4.bmp" $separateFilestest[4] = "C:\\Documents and Settings\\Tobias\\Desktop\\AutoITCombineTest\\allyourbase.cats" $separateFilestest[5] = "C:\\Documents and Settings\\Tobias\\Desktop\\AutoITCombineTest\\arebelongtous.cats" CMB_CombineFiles($unifiletest, $separateFilestest) CMB_ExtractFiles($unifiletest, $separateFilestest) #ce Func CMB_CombineFiles($unifileName, $separateFiles) local $CMB_SEPARATOR = "|" local $numOfFiles = UBound($separateFiles) For $i = 0 To $numOfFiles - 1 If NOT FileExists($separateFiles[$i]) Then Return -1 Next local $unifile = FileOpen($unifileName, 18) FileWrite($unifile, String($numOfFiles)) FileWrite($unifile, $CMB_SEPARATOR) For $i = 0 To $numOfFiles - 1 local $tempFileSize = FileGetSize($separateFiles[$i]) FileWrite($unifile, String($tempFileSize)) FileWrite($unifile, $CMB_SEPARATOR) Next For $i = 0 To $numOfFiles - 1 local $tempFile = FileOpen($separateFiles[$i], 16) FileWrite($unifile, FileRead($tempFile)) FileClose($tempFile) Next FileClose($unifile) Return(0) EndFunc Func CMB_ExtractFiles($unifileName, $separateFiles) local $unifile = FileOpen($unifileName, 16) local $numOfFiles = CMB_P_GetNext($unifile) local $separateFilesLengths[$numOfFiles] For $i = 0 To $numOfFiles - 1 $separateFilesLengths[$i] = Number(CMB_P_GetNext($unifile)) Next For $i = 0 To $numOfFiles - 1 local $tempFile = FileOpen($separateFiles[$i], 18) FileWrite($tempFile, FileRead($unifile, $separateFilesLengths[$i])) FileClose($tempFile) Next FileClose($unifile) EndFunc Func CMB_GetNumOfFiles($unifileName) local $unifile = FileOpen($unifileName, 16) local $numOfFiles = Number(CMB_P_GetNext($unifile)) FileClose($unifile) Return($numOfFiles) EndFunc Func CMB_P_GetNext($file) local $CMB_SEPARATOR = "|" local $tempString = "" While 1 local $tempChar = BinaryToString(FileRead($file, 1)) If($tempChar = $CMB_SEPARATOR) Then ExitLoop Else $tempString &= $tempChar EndIf WEnd Return($tempString) EndFunc 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