For the content that I create, I like to have full descriptions of things. But if someone asks me to share something, doing so with full descriptions would likely infringe on someone's copyright. (It is my understanding that you can copyright content, but not mechanics.)
So I came up with a Powershell script to redact descriptions. I can keep my own files with full descriptions and use a script to redact those descriptions if I choose to share the mechanics of my work.
I have included two methods within the script to protect original files, but you should still be aware that this script is not heavily tested. I recommend using it on a copy of your original files, or to at least backup your original files. I offer no warranties or guaranties of anything. Use this at your own risk.
That being said, here's the script.
So I came up with a Powershell script to redact descriptions. I can keep my own files with full descriptions and use a script to redact those descriptions if I choose to share the mechanics of my work.
I have included two methods within the script to protect original files, but you should still be aware that this script is not heavily tested. I recommend using it on a copy of your original files, or to at least backup your original files. I offer no warranties or guaranties of anything. Use this at your own risk.
That being said, here's the script.
Code:
### Source Path (Edit this to your preference.)
$filepath = "C:\ProgramData\Hero Lab\data\fatecore"
### Different subfolder for modified files to protect your originals.
### If this does not exist, the script will create it.
### (Edit this to your preference.)
$subfolder = "No_Descriptions"
### Source File (Ediit this to your preference.)
$oldfilename = "stuntspowers.user"
### Prefix for the modified filename.
### Additional measure to protect your original files.
### (Edit this to your preference.)
$newfilename = "NO_DESC_" + $oldfilename
### Everything that follows is procedural code.
### DO NOT edit anything below unless you understand the code.
### Delimiters for the description text.
$firststring = "description="""
$laststring = """ "
### Create a blank array to build the content for a new file.
[array]$newfile = @()
### Read the source file.
$oldfile = Get-Content "$filepath\$oldfilename"
### For each line in the source file, find and redact the description text.
foreach ($line in $oldfile) {
$startrange = ""
$endrange = ""
$startrange = $line.ToLower().IndexOf($firststring)
if ($startrange -ge 0) {
$startrange = $startrange + $firststring.Length
$endrange = $line.ToLower().IndexOf($laststring, $startrange)
$range = $endrange - $startrange
if ($range -gt 0) {
$description = $line.Substring($startrange,$range)
$line = $line.Replace($description,"")
} # if ($startrange -ge 0)
} # if ($startrange -ge 0)
[array]$newfile = $newfile + $line
} # foreach ($line in $oldfile)
### Check if the subfolder exists.
### If it does not, create it.
$SubfolderExists = Test-Path "$filepath\$subfolder"
if ($SubfolderExists -eq $False) {mkdir "$filepath\$subfolder"}
### Write the redacted content to a new file in the subfolder.
$newfile | Set-Content "$filepath\$subfolder\$newfilename"