-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderScanner.html
More file actions
42 lines (39 loc) · 1.37 KB
/
FolderScanner.html
File metadata and controls
42 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="uk">
<head>
<meta charset="UTF-8">
<title>Сканування папки</title>
</head>
<body>
<button id="selectFolder">Вибрати папку</button>
<pre id="fileList"></pre>
<script>
// Рекурсивная функция для получения файлов из папки
async function getFilesRecursively(dirHandle, path = '') {
const files = [];
for await (const entry of dirHandle.values()) {
const entryPath = path + entry.name;
if (entry.kind === 'file') {
files.push(entryPath);
} else if (entry.kind === 'directory') {
const nestedFiles = await getFilesRecursively(entry, entryPath + '/');
files.push(...nestedFiles);
}
}
return files;
}
document.getElementById('selectFolder').addEventListener('click', async () => {
try {
// Открытие диалога выбора папки
const dirHandle = await window.showDirectoryPicker();
const allFiles = await getFilesRecursively(dirHandle);
// Вывод всех файлов
document.getElementById('fileList').textContent = allFiles.join('\n');
console.log(allFiles);
} catch (err) {
console.error('Помилка або відміна користувачем:', err);
}
});
</script>
</body>
</html>