scripts/folder-listing-node/index.mjs

63 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2023-04-11 16:12:27 +02:00
// lister les dossiers dans le dossier stockage syncable pour en tirer une liste de dates d'évènements
2023-07-29 16:52:53 +02:00
import fs from 'fs'
2023-04-11 16:12:27 +02:00
let suffix = ''
2023-07-29 16:52:53 +02:00
const folder_photo = `/home/poule/encrypted/stockage-syncable/photos${suffix}`
2023-04-11 16:12:27 +02:00
/**
* obtenir une liste des dossiers uniquement dans le dossier courant
* @param path
* @returns {*}
*/
2023-07-29 16:52:53 +02:00
function getDirectories (path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + '/' + file).isDirectory()
})
2023-04-11 16:12:27 +02:00
}
/**
* lister 3 sous niveaux de dossiers
* @param folders
*/
2023-07-29 16:52:53 +02:00
function recursiveListing (folders) {
for (let dossier of folders) {
dossier = dossier.trim()
console.log(folder_photo + '/' + dossier)
let subdir1 = folder_photo + '/' + dossier
let listing = getDirectories(subdir1)
if (listing.length) {
// console.log('', listing)
for (let d2 of listing) {
let subdir2 = folder_photo + '/' + dossier + '/' + d2
console.log(subdir2)
let listing2 = getDirectories(subdir1)
if (listing2.length) {
for (let d3 of listing2) {
let subdir3 = subdir2 + '/' + d3
console.log(subdir3)
let listing3 = getDirectories(subdir2)
if (listing3.length) {
for (let d4 of listing3) {
let subdir4 = subdir3 + '/' + d4
console.log(subdir4)
}
}
}
}
}
}
}
2023-04-11 16:12:27 +02:00
}
/**
* faire un premier passage sur la racine du dossier de photos
* @type {*}
*/
getDirectories(folder_photo)
recursiveListing(getDirectories(folder_photo))