scripts/folder-listing-node/index.mjs

55 lines
1.5 KiB
JavaScript
Raw 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
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)
}
}
}
}
}
}
/**
* faire un premier passage sur la racine du dossier de photos
* @type {*}
*/
getDirectories(folder_photo)
recursiveListing(getDirectories(folder_photo))