add recursive function to get subfolders

Co-authored-by: Avior <github@avior.me>
This commit is contained in:
Edhueppe 2023-02-03 13:38:01 +01:00
parent 99c872fe97
commit 9e1c476fb3
44 changed files with 64 additions and 33 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

View File

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View File

@ -1 +1 @@
{"image2.jfif":"0d6b9895abedf59b3dc015ad94f0af50a85050219381d227ab1075f04e099494","image3.jfif":"883389005f159159cd623748e2235516067b04061037cb0f1d0d27ebfff91c33"}
{"./images/folder 2/Nouveau dossier 23/image3.jfif":"ff3f51cd80b775b8f74f674b9a17d050df5575b7600381ec3b615f54ff42f8eb","./images/folder 2/OIP (2).jfif":"0b3bf63a6990762e9143019805c9f56ef016e4270e7dca65c5ac9bea138e929c","./images/folder 3/Nouveau dossier/image2.jfif":"9d20202e67804602fd4d0c8d28a92b2e7b3af3d9a9b772816d80dee2d13d943d","./images/folder 4/OIP.jfif":"31f5d9c67ee42d268255965f1bbddd987dac6844a4ed14e5fdf9e8a2fc37f0ee","./images/OIP (1).jfif":"dff223d9e4a51801559c84709c162f6d907435132f6d953ccc246fb24830063d","./images/folder 1/Nouveau dossier 11/OIP (1).jfif":"19ce534a376419da2f1563eeacc74563f6863dfd01b033bc09972b10427ff405","./images/folder 1/Nouveau dossier 12/OIP (3).jfif":"a0f5c85435b5b715f309c675d9e2212d091d6948920161046c6b9379eb19622a","./images/folder 1/Nouveau dossier 12/OIP.jfif":"c0b9a5291c675000bd820afa2c22ad955c5217006b9fa4f6ae068bb2bb3cfd15","./images/folder 1/OIP (2).jfif":"1a2ed303576415dad4983b248c6c050ccf51c1a6cf70fdab54e3a4213defddde","./images/folder 2/Nouveau dossier 22/télécharger (2).jfif":"c8c59fc044f77570957e70bb961771704afcb55a0f773f3dac611616787f3715","./images/folder 2/Nouveau dossier 22/télécharger (3).jfif":"4b7831419a7ca51d871cf5ab2cd57a15c297ab1a01c31e8902d07e08e8c08aad","./images/folder 2/Nouveau dossier 23/.image3.jfif":"e8e1a17cab46733babad5d87e2a61a4ea37be798a76c1c9682b7739e3c31f39b","./images/folder 2/télécharger (1).jfif":"da65ead7bef4089f741ca63efbe5bd8c23d813221b641eb4dd0546a0805b7087","./images/folder 3/Nouveau dossier/.image2.jfif":"56bf384055c610d8f43a9b35688169265a01c044298be03f017ab3ec6eb2f439","./images/folder 4/Nouveau dossier (2)/OIP (4).jfif":"a8c0540186e1e79d42b8ccf703cfe63cd2e2eae4878f13f6531a1c40211a9765","./images/folder 4/Nouveau dossier (2)/télécharger.jfif":"8b639c130dc8e180e90283e62ddeb5dbcbf36c19af82d04790685cf280623702","./images/folder 1/.OIP (2).jfif":"56f99ac641481dd87ece913ef608138e1fd37d4db32bd8976831b5508ae11b4a","./images/folder 1/Nouveau dossier 11/.OIP (1).jfif":"ade381446ee6cc14bec8c5e8afa69d5bdbbae034114451f65bb58ba93cd5f936","./images/folder 1/Nouveau dossier 12/.OIP (3).jfif":"8a672664d8fcc0925785337e35c725c07578c140039ff31efb1f91e92fe353e0","./images/folder 1/Nouveau dossier 12/.OIP.jfif":"cce93f36de35871bcad6608863d37d6c41058b1b31571dae0d6e358c0e1bc351","./images/folder 2/.télécharger (1).jfif":"503a9479692a0aede74b1652d79d449896c2dea13ae766b7b758a656c36cac8b","./images/folder 2/Nouveau dossier 22/.télécharger (2).jfif":"506dcbc3843a26ef923381a5b704c0b9fdffc039bac6c0eaf518575b16cb573b","./images/folder 2/Nouveau dossier 22/.télécharger (3).jfif":"e97873807b5d8dbec9904ed65bd65b92adaa25ec38950dbd221998658c8507f7","./images/folder 2/Nouveau dossier 23/..image3.jfif":"f2d98430ae5704c317675c3dec1c311ec6be7f725ffbfa98dd123950dc3a62a0","./images/folder 3/Nouveau dossier/..image2.jfif":"da84dc7ff498f730989f852829d676b9fb9c134d11008c9ac93033cbac2197b7","./images/folder 4/Nouveau dossier (2)/.OIP (4).jfif":"6edd87b15bdb861395be0ed66834fcfc57684138324dc4cf49cc8badc3dc8037","./images/folder 4/Nouveau dossier (2)/.télécharger.jfif":"1aeb0a04dd8ba7ff75575e50155e52785400971dcc855912c81d94ce7e261a8e"}

1
pouet.json Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -3,13 +3,38 @@
import Jimp from 'jimp'
import fs from 'fs/promises'
import crypto from 'crypto'
import path from 'path'
;(async (folder: string) => {
/**
*
*
* @param path the folder to search
*
* @return the list of files included in this folder/subfolders
*/
async function filesList(Path: string): Promise<Array<string>> {
const files: Array<string> = []
const subFolders = await fs.readdir(Path)
for await (const subFolder of subFolders)
{
const stats = await fs.stat(Path + '/' + subFolder)
if (stats.isDirectory()) {
files.push(...await filesList(Path + '/' + subFolder))
} else {
files.push(Path + '/' + subFolder)
}
const files = await fs.readdir(folder)
}
return files
}
(async (dirPath: string) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const files = await filesList(dirPath)
console.log(files)
// Filtre cool
const imageFiles = files.filter((file) => !file.startsWith('.'))
const imageFiles = (await files).filter((file) => file.endsWith('.jfif'))
const data = (await fs.readFile('./output.json')).toString('utf8')
let json: Record<string, string> = {}
@ -28,8 +53,7 @@ import crypto from 'crypto'
const hash = crypto.createHash('sha256')
hash.setEncoding('hex')
// the text that you want to hash
const readI = await fs.readFile(`${folder}/${file}`)
const readI = await fs.readFile(`${file}`)
hash.write(readI)
hash.end()
const sha256sum = hash.read()
@ -51,9 +75,13 @@ import crypto from 'crypto'
// read image
image.sepia()
// change name
const newFileName = '.' + file
const bFile = path.basename(file)
const pName = path.dirname(file)
console.log(bFile)
const newFileName = pName + '/.' + bFile
console.log('newfilename:' + newFileName)
// save image with new file name
await image.writeAsync(`${folder}/${newFileName}`)
await image.writeAsync(`${newFileName}`)
console.log('Images have been inverted and rename ' + '.' + file)
}

37
test.js
View File

@ -1,13 +1,30 @@
function pouet(liste) {
if (liste.length === 0) return []
const result = []
/**
* @type string | Array<string>
*/
const item = liste.pop()
if (typeof item === 'object') {
result.push(...pouet(item))
} else {
// typeof item === 'string'
if (item.charCodeAt(0) % 2 === 1) {
// item est pair
result.push(item)
}
}
result.push(...pouet(liste))
return result
}
(async () => {
console.log('a')
await new Promise((res) => {
setTimeout(() => {
console.log('b')
res()
}, 1000)
})
console.log('c')
const entree = ['a', ['b', 'c', 'd', ['e', ['f'], 'g'], 'h', 'i', 'j'], 'k', 'l', 'm', ['n', 'o', 'p'], 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
console.log(
pouet(entree)
)
})()

15
test.ts
View File

@ -1,15 +0,0 @@
setTimeout(() => {
console.log('pouet')
}, 1000)
(async () => {
})()