53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Chemin du dossier INBOX_a_assembler
|
|
const inboxDir = '/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/INBOX_a_assembler';
|
|
|
|
// Chemin du dossier de destination pour les séquences assemblées
|
|
const outDir = '/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/INBOX_a_assembler';
|
|
|
|
// Parse les fichiers dans le dossier INBOX_a_assembler
|
|
fs.readdirSync(inboxDir).forEach((file: any) => {
|
|
|
|
console.log('file', file)
|
|
|
|
|
|
let dossier = file
|
|
// Ignorer les fichiers qui ne sont pas des dossiers
|
|
if (!fs.lstatSync(path.join(inboxDir, dossier)).isDirectory()) return;
|
|
|
|
console.log('dossier', dossier)
|
|
// Extraire le numéro du nom de fichier
|
|
const number = dossier.match(/\d+/);
|
|
|
|
console.log('number', number[0])
|
|
// Si le dossier de la séquence existe déjà, ignorez-le
|
|
// if (fs.existsSync(path.join(outDir, number[0]))) return;
|
|
|
|
// Créer le dossier de la séquence
|
|
// fs.mkdirSync(path.join(outDir, number[0]));
|
|
|
|
// Copier les photos front et back dans le nouveau dossier
|
|
let lepath_source_front = path.join('' + inboxDir, number[0] + 'GFRNT', '*.JPG')
|
|
let lepath_source_back = path.join('' + inboxDir, number[0] + 'GBACK', '*.JPG')
|
|
let lepath_destination = path.join('' + outDir, number[0])
|
|
|
|
console.log('source front', lepath_source_front)
|
|
console.log('source back', lepath_source_back)
|
|
console.log('destination', lepath_destination)
|
|
|
|
|
|
const files_front = fs.readdirSync(path.join(inboxDir, number[0] + 'GFRNT'));
|
|
console.log('files front', files_front.length)
|
|
if (files_front.length > 2) {
|
|
fs.renameSync(lepath_source_front, lepath_destination);
|
|
}
|
|
const files_back = fs.readdirSync(path.join(inboxDir, number[0] + 'GBACK'));
|
|
console.log('files back', files_back.length)
|
|
if (files_back.length > 2) {
|
|
fs.renameSync(lepath_source_back, lepath_destination);
|
|
|
|
}
|
|
|
|
}); |