From 9745140b30f6acf799a595760a8980d3f4664d17 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Tue, 11 Apr 2023 16:12:27 +0200 Subject: [PATCH] node listing subfolders --- folder-listing-node/index.mjs | 54 +++++++++++++++++++++++++++ folder-listing-node/package-lock.json | 24 ++++++++++++ folder-listing-node/package.json | 5 +++ 3 files changed, 83 insertions(+) create mode 100644 folder-listing-node/index.mjs create mode 100644 folder-listing-node/package-lock.json create mode 100644 folder-listing-node/package.json diff --git a/folder-listing-node/index.mjs b/folder-listing-node/index.mjs new file mode 100644 index 00000000..6b625940 --- /dev/null +++ b/folder-listing-node/index.mjs @@ -0,0 +1,54 @@ +// 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)) diff --git a/folder-listing-node/package-lock.json b/folder-listing-node/package-lock.json new file mode 100644 index 00000000..2762f9d3 --- /dev/null +++ b/folder-listing-node/package-lock.json @@ -0,0 +1,24 @@ +{ + "name": "folder-listing-node", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "fs": "^0.0.1-security" + } + }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + } + }, + "dependencies": { + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + } + } +} diff --git a/folder-listing-node/package.json b/folder-listing-node/package.json new file mode 100644 index 00000000..7ea3a904 --- /dev/null +++ b/folder-listing-node/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "fs": "^0.0.1-security" + } +}