Created
February 3, 2023 21:08
-
-
Save palaniraja/939fbb69f4bf82ac216866414b55e301 to your computer and use it in GitHub Desktop.
IIS directory listing sort by date. assuming your IIS set to list these 3 column (date, DIR|Size, Link)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = Array.from(document.querySelector("pre").childNodes) | |
links = 0 | |
dates = [] | |
links = [] | |
meta = [] | |
dirOrSize = [] | |
i = 0; | |
arr.forEach((el) => { | |
if (i<4) { //skip initial few lines | |
i++ | |
return | |
} | |
if (el.tagName == 'BR') { | |
//ignore | |
} | |
else if (el.tagName == 'A') { | |
links.push(el.href) | |
meta.push(el.text) | |
} | |
else if (el.tagName == undefined) { | |
dt = el.data.slice(0,19) | |
dates.push(dt) | |
ds = el.data.slice(20) | |
if (ds.trim() == "<dir>") { | |
dirOrSize.push(ds.replace("<dir>", " DIR ")) | |
} else { | |
dirOrSize.push(ds) | |
} | |
} | |
}) | |
descDates = [...dates].sort().reverse() | |
console.log(dates) | |
console.log(descDates) | |
newHtml = "" | |
descDates.forEach(el => { | |
idx = dates.indexOf(el) | |
newHtml += "<div>"+dates[idx]+""+dirOrSize[idx]+"<a href='"+links[idx]+"'>"+meta[idx]+"</a></div>" | |
}) | |
// console.log(meta) | |
document.querySelector("pre").innerHTML=newHtml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://bookmarkify.it/56721