AutoHotkey: Combine file parts

From TotalcmdWiki
Jump to navigation Jump to search

This script combines file parts created using File - Split File. You can choose the extension of the output file.

Usage:

  • create a button in the Button Bar or a Start menu entry pointing to this script
  • enter "%L" in the Parameters field
  • clear the Start path
  • use by selecting file parts file.001 - file.nnn (do not forget to sort in ascending order) and clicking on the script button (menu entry)
; Check number of parameters
; %0% is the number of parameters
; In "If" it must be referenced as 0, not %0%
IfNotEqual, 0, 1
{
	MsgBox, Error: Exactly one parameter "`%L" required.`n`nNumber of parameters passed: %0%`n`nExiting.
	Exit
}

; Check if listfile exists
IfNotExist, %1%
{
	MsgBox, Error: List file "%1%" not found.`n`nExiting.
	Exit
}

; Ask the user about the desired extension
InputBox, Extension, Extension, What is the desired extension (without dot)?, , , 120
IfEqual, ErrorLevel, 1
	Exit
FileReadLine, FirstFilePart, %1%, 1
StringGetPos, DotPos, FirstFilePart, ., R
StringLeft, OrigName, FirstFilePart, DotPos
OrigName = %OrigName%.%Extension%

; Check if output file does not already exist
IfExist, %OrigName%
{
	MsgBox, Error: Output file "%OutputFile%" already exists.`n`nExiting.
	Exit
}

; Create combine command string
CombineString = @copy /b%A_Space%
Loop, Read, %1%
{
	StringGetPos, BackslashPos, A_LoopReadLine, \, R
	StringTrimLeft, CurrFileName, A_LoopReadLine, BackSlashPos + 1
	CombineString = %CombineString% "%CurrFileName%" +
}
StringTrimRight, CombineString, CombineString, 1

CombineString = %CombineString%"%OrigName%"

; Execute
IfEqual, OS, Windows_NT
	Run, cmd /c %CombineString%
Else
	Run, command /c %CombineString%



Back to AutoHotkey