Jump to content

Recommended Posts

Posted

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.

Posted

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"

Posted

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.

Posted

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.

#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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...