Powershell script -- 2
Budget: $30 – $250 USD
Instructions:
Create a PowerShell script that goes through all files in a single directory.
(Not recursively through sub-directories).
1. The script starts by examining the file name and extracting one or two colors. All files
end with either one or two RBG values (6: characters 0-9 and A-F). All files
are SVG files - plain text.
For example:
printable-angel-clipart-882222-ffff00.svg (RGB: 882222 and ffff00)
angel-cookie-cutter-pattern-dddddd.svg (RGB: dddddd)
2. Inside the files, substitute all occurrences of these values (and #sign) with
url(#checkerboard-pattern-1)
For example (first file listed above)
#882222 -> url(#checkerboard-pattern-1)
#ffff00 -> url(#checkerboard-pattern-1)
OR (second file listed above)
#dddddd -> url(#checkerboard-pattern-1)
3. Search for "<defs". Replace with "XYZ <defs" Where XYZ is listed below. Can read this
data from attached file or hard coded into script.
4. One of the first lines of the script should contain a path name which I could easily modify.
For example: $base_dir = 'C:\Temp'
Two sample images are provided. SVG files can be opened with numerous applications
including a regular browser (e.g., FireFox, Google Chrome, etc.)
----- BEGIN XYZ --------------
<defs>
<pattern
id="checkerboard-pattern-1"
x="0"
y="0"
width="16"
height="16"
patternUnits="userSpaceOnUse">
<rect
fill="#ff0000"
x="0"
y="0"
width="8"
height="8" />
<rect
fill="#ffffff"
x="8"
y="0"
width="8"
height="8" />
<rect
fill="#ffffff"
x="0"
y="8"
width="8"
height="8" />
<rect
fill="#ff0000"
x="8"
y="8"
width="8"
height="8" />
</pattern>
</defs>
----- END XYZ --------------
The code below might be helpful???
$base_dir = 'C:\path\path'
Get-ChildItem $base_dir -Recurse -Include "*.svg" -PipelineVariable F |
ForEach-Object { (Get-Content $_.FullName) | ForEach-Object {$_ -replace 'dddddd',
@(if (@($F.FullName.Length -ge 10) -and @($F.FullName.Substring($F.FullName.Length-10,6) -match '^[0-9,A-F,a-f]+$')) {$F.FullName.Substring($F.FullName.Length-10,6);} else {"dddddd";}) } | Set-Content $_.FullName }
Create a PowerShell script that goes through all files in a single directory.
(Not recursively through sub-directories).
1. The script starts by examining the file name and extracting one or two colors. All files
end with either one or two RBG values (6: characters 0-9 and A-F). All files
are SVG files - plain text.
For example:
printable-angel-clipart-882222-ffff00.svg (RGB: 882222 and ffff00)
angel-cookie-cutter-pattern-dddddd.svg (RGB: dddddd)
2. Inside the files, substitute all occurrences of these values (and #sign) with
url(#checkerboard-pattern-1)
For example (first file listed above)
#882222 -> url(#checkerboard-pattern-1)
#ffff00 -> url(#checkerboard-pattern-1)
OR (second file listed above)
#dddddd -> url(#checkerboard-pattern-1)
3. Search for "<defs". Replace with "XYZ <defs" Where XYZ is listed below. Can read this
data from attached file or hard coded into script.
4. One of the first lines of the script should contain a path name which I could easily modify.
For example: $base_dir = 'C:\Temp'
Two sample images are provided. SVG files can be opened with numerous applications
including a regular browser (e.g., FireFox, Google Chrome, etc.)
----- BEGIN XYZ --------------
<defs>
<pattern
id="checkerboard-pattern-1"
x="0"
y="0"
width="16"
height="16"
patternUnits="userSpaceOnUse">
<rect
fill="#ff0000"
x="0"
y="0"
width="8"
height="8" />
<rect
fill="#ffffff"
x="8"
y="0"
width="8"
height="8" />
<rect
fill="#ffffff"
x="0"
y="8"
width="8"
height="8" />
<rect
fill="#ff0000"
x="8"
y="8"
width="8"
height="8" />
</pattern>
</defs>
----- END XYZ --------------
The code below might be helpful???
$base_dir = 'C:\path\path'
Get-ChildItem $base_dir -Recurse -Include "*.svg" -PipelineVariable F |
ForEach-Object { (Get-Content $_.FullName) | ForEach-Object {$_ -replace 'dddddd',
@(if (@($F.FullName.Length -ge 10) -and @($F.FullName.Substring($F.FullName.Length-10,6) -match '^[0-9,A-F,a-f]+$')) {$F.FullName.Substring($F.FullName.Length-10,6);} else {"dddddd";}) } | Set-Content $_.FullName }