- 1 year ago
Powershell: Combine multiple html files into one single html file
To combine multiple HTML files into a single HTML file using PowerShell, you can read the content of each file and append it to a new file. Here's an example:
powershell# List of HTML files to combine
$sourceFiles = @(
"file1.html",
"file2.html",
"file3.html"
)
# Destination file to store the combined HTML
$destinationFile = "combined.html"
# Create a new file for combined HTML
New-Item -ItemType File -Path $destinationFile -Force | Out-Null
# Loop through the source files and append their content to the destination file
foreach ($file in $sourceFiles) {
$content = Get-Content -Path $file -Raw
Add-Content -Path $destinationFile -Value $content
}
In the above example, you need to specify the list of HTML files ($sourceFiles
) that you want to combine. Adjust the file names and paths as needed.
Specify the desired destination file ($destinationFile
) where the combined HTML will be stored.
The script creates a new file using New-Item
and then uses a foreach
loop to iterate through each source file. It reads the content of each file using Get-Content -Raw
to retrieve the content as a single string.
The content of each file is then appended to the destination file using Add-Content
.
After running the script, the specified destination file will contain the combined HTML from all the source files.
Please note that the order of combining files depends on the order specified in the $sourceFiles
array. Adjust the order of the array elements to control the sequence of combining the HTML files.