Last active
October 15, 2022 12:39
-
-
Save sjain882/9e6d0651a54695123c5ecf7898bb9329 to your computer and use it in GitHub Desktop.
Outputs a table listing all of your OMSI maps next to their total number of tiles - largest at the top - to a file with date and time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Outputs a table listing all of your OMSI maps next to their total number of tiles - largest at the top - to a file with date and time. | |
# Requires PowerShell 5.0 or above (Windows 10) | |
# Created by https://github.com/sjain882 (sjain / shanie) | |
# Latest version at https://gist.github.com/sjain882/9e6d0651a54695123c5ecf7898bb9329 | |
# Instructions: | |
# | |
# 1. Open PowerShell from your start menu as administrator, paste this command then hit Enter (to be able to run the script): Set-ExecutionPolicy Bypass -Scope Process -Force | |
# | |
# 2. Download this file to your **OMSI 2 maps folder** - it must be run from there - e.g.: | |
# C:\Program Files (x86)\Steam\steamapps\common\OMSI 2\maps | |
# D:\Games\OMSI 2\maps | |
# | |
# 3. Run the script. | |
# | |
# 4. Wait till it says "Finished." | |
# | |
# 5. Access the text file created in your maps folder called `My largest OMSI maps (in tiles) DD-MM-YYY_HHMMSS.txt` | |
# Determine name of file to output to | |
$baseName = 'My largest OMSI maps (in tiles) ' | |
$dateTime = Get-Date -Format 'dd-MM-yyyy_HHmmss' | |
$extension = '.txt' | |
$fileName = ($baseName + $dateTime + $extension) | |
$outputPath = Join-Path -Path $PSScriptRoot -ChildPath $fileName | |
# Create file | |
New-Item -Path $outputPath | |
# Strings | |
$header1 = '----------------------------------------------' | |
$header2 = 'Number of tiles | Map name' | |
$header3 = '----------------------------------------------' | |
# Iterate over all OMSI maps | |
foreach ($folder in Get-ChildItem -Directory) | |
{ | |
# Get count of *.map | |
(Get-ChildItem -LiteralPath $folder -Filter '*.map' -File -Recurse -Depth 0).Count | Out-File -Append -NoNewline -FilePath $outputPath | |
# Alternative stricter options (incase of cmd regex like *.map* automatically): | |
# (Get-ChildItem -LiteralPath $folder -Filter '*.map' -File -Recurse | Where-Object { $_.Extension -match '\.(map)$' }).Count | Out-File -Append -NoNewline -FilePath $outputPath | |
# (Get-ChildItem -LiteralPath $folder -File -Recurse | Where-Object { $_.FullName -like "*.map" }).Count | Out-File -Append -NoNewline -FilePath $outputPath | |
# Insert tab | |
' ' | Out-File -Append -NoNewline -FilePath $outputPath | |
# Insert map name and new line | |
$folder.Name | Out-File -Append -FilePath $outputPath | |
} | |
# The results | |
$output = Get-Content $outputPath | |
# The results sorted by highest count of *.map files | |
$sorted = $output -split '\r?\n' | Sort-Object -Descending { [int] (-split $_)[0] } | |
# Prepend table header and overwrite same file with final contents | |
$header1 | Out-File -FilePath $outputPath | |
$header2 | Out-File -Append -FilePath $outputPath | |
$header3 | Out-File -Append -FilePath $outputPath | |
$sorted | Out-File -Append -FilePath $outputPath | |
# Indicate status to user | |
Write-Output "`n" | |
Write-Output "Finished!" | |
Write-Output "`n" | |
# Wait for user confirmation to close window | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment