• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Powershell script to redact descriptions.

EightBitz

Well-known member
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.

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"
 
I'm just getting back into HL, but I always wondered about something like this. Might come in handy if I ever actually achieve what I am going for.
 
Very cool. Thanks for sharing.

Not a problem. I appreciate other people sharing their work. I'm not a whiz with data files, so I share what I can.

Next step is to go through the steps of sharing my Dresden Files stuff through a URL, now that I can easily remove all descriptions. :-)
 
Back
Top