Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Facebook Twitter Instagram
Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Tech News Today
Home»Windows»How to Split Files in Windows Quickly?

How to Split Files in Windows Quickly?

Abhishek SilwalBy Abhishek SilwalJuly 28, 2022
how to split files

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.

Table of Contents

  • How to Split Files in Windows
    • Split Files Using a Custom Script
    • Split File Using GNU Utilities for Win32
    • Split File Using Third-party Applications

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.

how-to
Abhishek Silwal
  • LinkedIn

Abhishek Silwal is an Electronics Engineer and a technical writer at TechNewsToday. He specializes in troubleshooting a wide range of computer-related issues. His educational background in Electronics Engineering has given him a solid foundation in understanding of computers. He is also proficient in several programming languages and has worked on various robotics projects. Even in his early days, he used to tinker with various computer components, both hardware, and software, to satiate his curiosity. This experience has given him a breadth of experience that goes beyond his educational qualification. Abhishek has been writing articles on dealing with varieties of technical issues and performing specific tasks, especially on a Windows machine. He strives to create comprehensive guides on fixing many system and hardware issues and help others solve their problems. You can contact him at abhisheksilwal@technewtoday.com

Related Posts

amd-software-not-opening

How to Fix AMD Software Not Opening

March 3, 2023
how to create a folder

7 Ways to Create a Folder on Windows

March 3, 2023
turn off automatic updates windows

How to Turn Off Automatic Updates on Windows

March 2, 2023
Memory-Compression

What is Memory Compression in Windows? Should You Enable or Disable It

March 1, 2023
dism-vs-sfc-vs-chdsk

DISM, SFC, CHKDSK: What’s the Difference

February 28, 2023
how-to-open-exe-file

4 Ways to Open EXE File

March 2, 2023
View 2 Comments

2 Comments

  1. Dill Aqa on August 15, 2022 11:59 pm

    Hello dear!
    I want a script like above for windows with the some changes, I want to split a folder into some equal file and get back all of them into a folder without any error and problem. could you help me please!?

    best regards

    Reply
    • Abhishek on August 16, 2022 12:13 pm

      Could you please clarify some things for me?
      Do you want to split a folder or a file?

      If it’s a file, the script in the article works perfectly in splitting the files into equal parts.

      However, if you want to split a folder along with its contents, you can only compress and split the folder by using compression tools like WinRAR and 7-Zip.

      Reply

Leave A Reply Cancel Reply

Latest Posts
Memory-Compression

What is Memory Compression in Windows? Should You Enable or Disable It

March 1, 2023
dism-vs-sfc-vs-chdsk

DISM, SFC, CHKDSK: What’s the Difference

February 28, 2023
bios-settings-for-gaming

Best BIOS Settings for Gaming

February 16, 2023
You may also like
how-to-clean-hp-printer-rollers

How to Clean HP Printer Rollers

March 3, 2023
keyboard input lag

9 Ways to Fix Keyboard Input Lag

March 3, 2023
keyboard key is stuck

How to Fix a Stuck Key on a Keyboard

March 3, 2023
Recommended
Cookie Clicker Garden Guide

Cookie Clicker Garden Guide to Unlocking Every Seed

September 26, 2021
monitor no signal

Computer Turns On But Monitor Says No Signal (9 Ways To Fix)

November 10, 2022
Facebook Twitter Pinterest
  • Home
  • About Us
  • Our Team
  • Editorial Guidelines
  • Privacy Policy
  • Affiliate Disclosure
© 2023 TechNewsToday, editor@technewstoday.com | Tech Central Pvt. Ltd.

Type above and press Enter to search. Press Esc to cancel.