Home » Support » Tutorials/Power Tips » UltraEdit » Combine All Open Files into a Single Destination File
IDM Power Tips

Combine All Open Files into a Single Destination File

Have you ever needed to combine multiple files into a single destination (output) file? UltraEdit/UEStudio allows you to insert a file into the active file, but there is not a quick function to combine a list of files. This may not be the type of feature that many users would want to use daily, but every once in a while you may need to combine a group of files. The following power tip will show you how to use a script and tool to combine all the files open in the editor.

The method we propose for doing this will take the following actions:

  1. A script will gather all open files in the editor and produce a batch file that essentially combines all the open files into an output (destination) file. The default batch file is c:\temp\combine_files.bat.
  2. The script will save the batch file to a location on your system (the default is c:\temp\output_file.txt).
  3. When the file has been saved, the script will run a Tool that simply executes the batch file.

Step 1: The Script

You will need to add the following script to UltraEdit/UEStudio.

  1. Copy/paste the contents of the script below into a new file in UltraEdit/UEStudio.
  2. Save the file to your system in a location which you will remember
  3. Go to the Scripting menu, and select Scripts
  4. Click on Add to add the script to the script list. When the "open" dialog appears, simply browse to the location of the script. After you have added the script, you should see the script in the list.

    Combine Multiple Files

  5. You are done adding the script, so you can now click OK.

//---------------------------------------------
//
// This script will create a batch file that combines all
// open files into a single destination file.
// When the batch file is complete, the script will execute
// a tool that runs the batch file.
// Important Note:
// This script requires a Tool called "Run Batch" that executes
// the batch file as defined by the variable "batFile"
//
//---------------------------------------------

var batFile = "c:\\temp\\combine_files.bat";
var outputFileName = "c:\\temp\\output_file.txt";
var toolName = "Run Batch";

//---------------------------------------------
// DO NOT CHANGE ANYTHING BELOW THIS LINE //
//---------------------------------------------

//Get list of open files and create the command string

var fileNames = "";
for (var x = 0; x < UltraEdit.document.length; ++x) {
  if (x < (UltraEdit.document.length - 1)) {
    fileNames = fileNames + "\"" + UltraEdit.document[x].path + "\"+";
  } else {
    fileNames = fileNames + "\"" + UltraEdit.document[x].path + "\"";
  }
}

//create batch file

UltraEdit.newFile();
UltraEdit.activeDocument.write("copy " + fileNames + " " + outputFileName);
UltraEdit.saveAs(batFile);

//Run batch file

UltraEdit.runTool(toolName);

Step 2: The Tool

Now that you have created the script and added it to the editor, you will need to create the tool that runs the batch file.

To create the tool, go to the Advanced menu and click on Tool Configuration.

Click on the Insert button to create a new tool

Command Tab:

  1. You will now need to name the tool. In the script, the tool name is defined in the variable "toolName". The default tool name is "Run Batch".
  2. The command line is simply the name of the batch file. In the script, the batch file name is defined in the variable "batFile". The default name is combine_files.bat.
  3. The working directory is the path to the batch file, in our example we are using "C:\temp\".
  4. The Command Tab options should look like:

    Combine Multiple Files

Options Tab:

  1. Select the DOS Program radio button
  2. Since the files will be combined by DOS, you will want to be sure that all open files are saved so the combined file reflects the most current version of the file. Therefore, you will need to check "Save all files first".
  3. The result should look something like:

    Combine Multiple Files

Output Tab:

  1. Select the "Append to Existing" radio button and the "No Replace".
  2. The Output options should look like:

    Combine Multiple Files


Step 3: Combine and Run!

The setup is complete! To run the script, simply open the files you want to combine then go to the Scripts menu and run the script. You can also execute the script from the script list if it is open.

Combine Multiple Files

Important note: make sure you only open the files that you want to combine. The script will combine all files open in the editor, so if you have extra files open, it will combine those into the output file as well.


Back to power tips index


Buy Now
Upgrade
Download

Get your solution today!

UE/UC

Add UltraCompare to your purchase/upgrade of UltraEdit and complete your file management solution.

Your bundle license runs on Windows, Mac, and Linux.

Working on a team?

UEStudio

Check out UEStudio - designed for those who collaborate!


"We won't mince words:
UltraEdit is outstanding..."

Application Screenshots

Feature maps

Road trip, anyone?

UE Mobile

Bundle UE Mobile with your UE upgrade and save 50%!


Take the UltraEdit tour