I have a lot (think tens of thousands) of cfm files where I need to add a custom attribute to the HTML tags. I worked up a Javascript function that can update a single page. Can I open a file with Coldfusion, change it with Javascript, then save the changed file with Coldfusion? Can you do both of these with CFScript? Would I be better served to use Powershell? I think you open a cfm file in Powershell something like...
$file = 'C:\example.cfm'
$ie = New-Object -COM 'InternetExplorer.Application'
$ie.Navigate("file://$file")
And my Javascript function is...
var x = document.getElementsByClassName("ThisClass");
// Loop through ThisClass elements
for (i = 0; i < x.length; ++i)
{
// Get the string in the HTML
var y = x[i].innerHTML;
// Replace spaces with underscores
var newstring = y.replace(' ', '_');
// Add new attribute with spaceless value
x[i].setAttribute('ThisAttribute', newstring);
}
But how would do the Javascript stuff on the $ie file in Powershell? And then save the edited file? Any help or direction would be appreciated.