<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="file" id="files" onchange="getInfo()" webkitdirectory multiple="multiple">
<script src="./js/xlsx.full.min.js"></script>
<script>
function getInfo() {
const targetEl = document.getElementById('files')
const files = targetEl.files
if (files.length === 0) {
alert('当前选择的文件夹为空,请重新选择!')
return
}
const result = []
for (let i = 0; i < files.length; i++) {
const { name, webkitRelativePath: path, size } = files[i]
const type = name.substr(name.lastIndexOf('.') + 1)
result.push({
name,
path,
type,
size: (size / 1024 / 1024).toFixed(2),
sizeUnit: 'MB'
})
}
const ws = XLSX.utils.json_to_sheet(result, {
header: ['name', 'path', 'size', 'sizeUnit', 'type']
})
const wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, 'Bookmarks')
XLSX.writeFile(wb, "result.xlsx")
}
</script>
</body>
</html>