node listing subfolders
This commit is contained in:
parent
f1c1e11d50
commit
9745140b30
|
@ -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))
|
|
@ -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=="
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"fs": "^0.0.1-security"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue