I’d like to do some hygiene on a bloated images folder/directory for a website of mine. I’m a grade just above novice working with javascript, it seems like it might be possible achieve a solution using javascript…
The solution I’m searching for would in essence crawl the entire directory of html/asp/css files (all in one directory) and scrape any and all image file names. Then output those file names into a delaminated list (or facsimile of) so that I could then compare that “scraped” list to images directory list – therefore identifying a list of unused images by process of elimination.
This is a crud script (obviously missing a lot of code) I've use // to mark the logic I think will work but is obviously psuedo code.
var URL_LENGTH = document.SITEMAP.getElementsByName("URL").length;
vari=1;
varz=1;
var list = [];
var URLX = 'P' + NUMBER;
var NUMBER = 1;
var PAGE;
var MINE;
var PAT1 = /(.gif|.jpg|.png)/g;
var IMGNAME;
for (i=1;i<=URL_LENGTH;i++)
{
PAGE = document.SITEMAP.getElementById(URLX).innerHTML;
MINE = document.[PAGE].match(PAT1).length;
for (z=1;z<=MINE;z++)
{
//global for string ending with (.gif|.jpg|.png)
//find begining of the image name string by looking for /( |'|"|/)/ that come before (.gif|.jpg|.png)
//inserting image name string into value for var IMGNAME
list.push(IMGNAME);
}
NUMBER=NUMBER+1;
}
with the SITEMAP looking someting like this
<div name="URL" id="P1">page1</div>
<div name="URL" id="P2">page2</div>
<div name="URL" id="P3">page3</div>