Senior Member
Join Date: May 2013
Posts: 1,458
|
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" |
#1 |
Senior Member
Volunteer Data File Author
Join Date: Feb 2009
Posts: 173
|
Very cool. Thanks for sharing.
Authoring Kit Rule Sets (now with functioning links!): Qin: The Warring States Doctor Who: Adventures in Time and Space MEGS/BoH/DC Heroes (work in progress) |
#2 |
Member
Join Date: Aug 2013
Location: CA
Posts: 42
|
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.
|
#3 |
Senior Member
Join Date: May 2013
Posts: 1,458
|
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. :-) |
#4 |
|
|