How to Split Large Files in Windows

Transferring large files is a serious hassle, especially if you want to upload to the internet or use a removable drive with small storage.

It is possible to compress and split files using archive tools. However, you can’t individually use the split files without decompressing them to a single file.

So, in this article, we will provide different ways with which you can split files while making certain files such as audio, video, text, etc., readable even in split state.

How to Split Files in Windows Quickly?

How to Split Files in Windows

Here are the methods you can use to split files in Windows:

Split Files Using a Custom Script

Windows does not have a built-in utility or app to split a file. So, we have created a user-friendly custom PowerShell script for splitting and rejoining a file to help you out.

Since most people need to split a file according to a particular size, our custom script implements only this feature. You can use it to create split files with an input MB size.

If you want to split using any other sizes, you can change the code as we have directed in the comments (lines followed by #).

To Split the File

First, open Windows PowerShell as admin and enter the command Get-ExecutionPolicy -Scope CurrentUser. You can type powershell on Run and press Ctrl + Shift + Enter to run it as admin.

If it shows Restricted, Undefined or AllSigned, you can’t run the script. To change it, enter Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned.

If you want more information, please refer to our article on Running Scripts Is Disabled On This System.

After changing the execution policy, follow the instructions below:

  1. Open a text editor. To open notepad, enter notepad on Run.
  2. Copy the following code on the text editor:
# Function to Split File
function Split-File
{
    param
    (
        [Parameter(Mandatory)]
        [String]
        $Path,
        $SavePath,
        [Int32]
        $PartSizeBytes = 1MB
    )
    try
    {
        # Get separate parts of filename to construct new names
        $NameWithoutExtension = [IO.Path]::GetFileNameWithoutExtension($Path)
        $ParentDirectory = [IO.Path]::GetDirectoryName($Path)
        $Extension = [IO.Path]::GetExtension($Path)

        # Calculate total number of chunks possible
        $OriginalFile = New-Object System.IO.FileInfo($Path)
        $TotalPartsCount = [int][Math]::Log10([int]($OriginalFile.Length / $PartSizeBytes) + 1) + 1
        $ReadFile = [IO.File]::OpenRead($Path)
        $Count = 0
        $Chunk = New-Object Byte[] $PartSizeBytes
        $DataLeftFlag = $true

        # Read chunks till data is left
        while($DataLeftFlag)
        {
            # read individual chunks
            $ReadBytes = $ReadFile.Read($Chunk, 0, $Chunk.Length)
            
            # create filenames for the chunks
            $chunkFileName = "$SavePath\$NameWithoutExtension.{0:D$TotalPartsCount}$Extension" -f $Count
            $Output = $Chunk

            # For the final part, where the chunksize is less
            if ($ReadBytes -ne $Chunk.Length)
            {
                $DataLeftFlag = $false # No more data
    
                # Use the final chunk as the last part by shrinking the bytesize
                $Output = New-Object Byte[] $ReadBytes
                [Array]::Copy($Chunk, $Output, $ReadBytes)
            }
   
            # save the chunk to a file
            [IO.File]::WriteAllBytes($chunkFileName, $Output)
            ++$Count
        }
        $ReadFile.Close()
    }
    catch
    {
        throw "Can't split file ${Path}: $_"
    }
}
#Create dialog box to open file
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$null = $FileBrowser.ShowDialog()

# Ask for size # CHANGE THIS SECTION to ask for size in other units
# 1KB=1024Bytes, 1MB = 1024KB, 1GB = 1024TB
$NumMB = read-host -Prompt "Enter Size in MB"
$NumBytes = 1024*1024*($NumMB -as [int]) # This section converts the MB input to bytes

#Create dialog box to save file
Add-Type -AssemblyName System.Windows.Forms
$SaveFileBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$null = $SaveFileBrowser.ShowDialog()

# Call Split-File Function to Split file
Split-File -SavePath $SaveFileBrowser.SelectedPath  -Path $FileBrowser.FileName -PartSizeBytes $NumBytes -Verbose
  1. Go to File Save as.
  2. Set Save as type to All files and File name to Split.ps1.
  3. You can set any location you want. After you are done, click Save.
    split-save-as
  4. Now, navigate to the Split.ps1 file.
  5. Right-click on it and select Run with PowerShell.
    Run-with-PowerShell
  6. Navigate to and select the file you need to split.
  7. Click Open.
    select-file-to-split
  8. Enter the size you want for each split part.
    enter-size-in-mb
  9. Navigate to and select the the output folder and click Ok.
    save-file-location

You can also open PowerShell, change the directory to the Split.ps1 file’s location and enter .\Split.ps1 to run it.

To Join the File

First, ensure that PowerShell’s execution policy allows running scripts (see the above section). Then, follow the instructions below to join the files:

  1. Make sure the files you want to join have the same extension (not just in name) are present in the same location.
  2. Change their names as name.xx.extension, where xx represents the part number, for e.g., music.00.mp3.
    split-files-output
  3. Open a text editor and copy the following code on the editor.
# Function to Join File
function Join-File
{
    param
    (
        [Parameter(Mandatory)]
        [String]
        $Path,
        $SavePath
    )
    try
    {
        # Get separate parts of filename to construct new names
        $NameWithoutExtension = [IO.Path]::GetFileNameWithoutExtension($Path)
        $OutputName = $NameWithoutExtension.Split(".")[0]
        $ParentDirectory = [IO.Path]::GetDirectoryName($Path)
        $Extension = [IO.Path]::GetExtension($Path)

        # Get all files, in order
        $Files = Get-ChildItem -Path "$ParentDirectory\$OutputName.*$Extension" | Sort-Object -Property {
            $Name = [IO.Path]::GetFileNameWithoutExtension($_.Name)
            $Part = [IO.Path]::GetExtension($Name)
            if ($Part -ne $null -and $Part -ne '')
            {
                $Part = $Part.Substring(1)
            }
            [int]$Part
        }
  
        # Create output file
        $WriteFile = [IO.File]::OpenWrite($SavePath+"\"+$OutputName+$Extension)
  
        # Write on output file
        $Files |
        ForEach-Object {
            $bytes = [IO.File]::ReadAllBytes($_)
            $WriteFile.Write($bytes, 0, $bytes.Length)
        }
        $WriteFile.Close()
    }
    catch
    {
        throw "Can't join file ${Path}: $_"
    }
}
# Create dialog box to open file
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$null = $FileBrowser.ShowDialog()

# Create dialog box to save file
Add-Type -AssemblyName System.Windows.Forms
$SaveFileBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$null = $SaveFileBrowser.ShowDialog()


# Call Join-File Function to Join selected files
Join-File -SavePath $SaveFileBrowser.SelectedPath -Path $FileBrowser.FileName -Verbose
  1. Go to File Save as.
  2. Set Save as type to All files and File name to Join.ps1.
  3. You can set any location you want. After you are done, click Save.
  4. Now, navigate to the Join.ps1 file.
  5. Right-click on it and select Run with PowerShell.
  6. Navigate to and select one of the files you want to join.
    open-file-join
  7. Click Open.
  8. Navigate to and select the the output folder and click OK.

You can also run the script from PowerShell by entering .\Join.ps1 when on the file’s directory.

Split File Using GNU Utilities for Win32

While Windows doesn’t have a native utility to split and join files, GNU systems like UNIX and Linux systems do. If you have installed git-bash on your computer, you can use the Linux commands- split to divide a file and cat to join them from its CLI.

Many developers have created open-source projects to allow some GNU utilities on Windows, such as GNU CoreUtils for Windows. These utilities only rely on Microsoft C-runtime (msvcrt.dll) to run some GNU commands. They also include the split and cat utilities.

Here are some necessary information on using these commands:

  • The complete syntax to divide the file is split [options] file_name [new_files_prefix] where, the bracketed values are optional. You need to replace “file_name” and “new_files_prefix” with the relevant file names.
  • If you enter just split file_name, it will divide the file into sections containing 1000 lines each.
  • If you want to divide the files according to size, you can use the flag -b or –size for [options]. For instance, split -b 10m myfile.txt newfile.
  • To recombine the file, the syntax you need is cat file_part* > file. For instance, you can use cat file1.txt file2.txt file3.txt > merged_file.txt or cat file* > merged_file.
  • We recommend using full paths for the filenames if your current working directory is not the same as the location of the file you wish to split.

You can visit the GNU documentation on CoreUtils to learn more about how you can use these utilities.

Split File Using Third-party Applications

The previous solutions provide limited options for splitting a file on Windows. They also use Command-line Interfaces, so you need to familiar with such interfaces if you want to customize ways to split a file.

So most people prefer using third-party tools as it is more convenient and provide more features. Some reliable apps you can use for this purpose are 7-Zip, HJSplit, GSplit, Total Commander, Fastest File Splitter and Joiner, and so on.

Mohamed SAKHRI
Mohamed SAKHRI

I'm the creator and editor-in-chief of Tech To Geek. Through this little blog, I share with you my passion for technology. I specialize in various operating systems such as Windows, Linux, macOS, and Android, focusing on providing practical and valuable guides.

Articles: 1725

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *