scripts/folder-listing-node/index.mjs

63 lines
1.5 KiB
JavaScript

// lister les dossiers dans le dossier stockage syncable pour en tirer une liste de dates d'évènements
import fs from 'fs'
let suffix = ''
const folder_photo = `/home/poule/encrypted/stockage-syncable/photos${suffix}`
/**
* obtenir une liste des dossiers uniquement dans le dossier courant
* @param path
* @returns {*}
*/
function getDirectories (path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + '/' + file).isDirectory()
})
}
/**
* lister 3 sous niveaux de dossiers
* @param folders
*/
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)
}
}
}
}
}
}
}
}
/**
* faire un premier passage sur la racine du dossier de photos
* @type {*}
*/
getDirectories(folder_photo)
recursiveListing(getDirectories(folder_photo))