Skip to content

Instantly share code, notes, and snippets.

@palaniraja
Created February 3, 2023 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palaniraja/939fbb69f4bf82ac216866414b55e301 to your computer and use it in GitHub Desktop.
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)
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
@palaniraja
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment