diff --git a/rangement/finder.mjs b/rangement/finder.mjs index 20bb1e0a..6586ad1d 100644 --- a/rangement/finder.mjs +++ b/rangement/finder.mjs @@ -159,7 +159,7 @@ export default class finder { * examine plusieurs propriétés exif de date et retourne la plus ancienne * @param filepath */ - static findExifCreationDate (filepath) { + static async findExifCreationDate (filepath) { console.log('filepath', filepath) let dateAlreadyInFileName = finder.findFormattedDate(filepath) @@ -168,13 +168,13 @@ export default class finder { console.log('------ dateAlreadyInFileName', dateAlreadyInFileName) } - exifr.parse(filepath).then(exifData => { + await exifr.parse(filepath).then(exifData => { if (exifData) { let moments = [] - console.log('exif data : ', exifData) // Do something with your data! + // console.log('exif data : ', exifData) // Do something with your data! if (exifData.DateTimeOriginal) { // console.log('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data! moments.push(exifData.DateTimeOriginal) @@ -194,12 +194,10 @@ export default class finder { moments.push(exifData.FileInodeChangeDateTime) } if (exifData.FileModificationDateTime) { - // console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data! moments.push(exifData.FileModificationDateTime) } if (exifData.CreateDate) { - // console.log('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data! moments.push(exifData.CreateDate) } @@ -210,7 +208,10 @@ export default class finder { }) let minDate = moment.min(moments) - return minDate.format('Y-M-DTH:i:s') + // console.log('minDate :::::::::', minDate) + console.log('minDate :::::::::', minDate.format('yyyy-MM-DDTHH:mm:ss')) + + return minDate.format('yyyy-MM-DDTHH:mm:ss') } else { console.log('pas de exif data') return '' diff --git a/rangement/index.mjs b/rangement/index.mjs index f7641945..86dc43ad 100644 --- a/rangement/index.mjs +++ b/rangement/index.mjs @@ -19,7 +19,7 @@ import { } from './testFunctions.mjs' import finder from './finder.mjs' -let mini_arguments; +let mini_arguments console.log(' ') function parseArguments () { @@ -29,21 +29,19 @@ function parseArguments () { parseArguments() - function renameFile (originalFileName, fileMixedNewName) { fs.rename(originalFileName, fileMixedNewName, function (err) { if (err) console.log('rename ERROR: ' + err) }) } - function makeFileNameFromProperties (fileProperties) { - let tagPlace = ''; - if(fileProperties.tags.length){ + let tagPlace = '' + if (fileProperties.tags.length) { tagPlace = ' ' + tagSectionSeparator + ' ' } - return finder.cleanSpaces( fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+ ' ' + tagSectionSeparator + ' '+'.' ,'.') + return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+' ' + tagSectionSeparator + ' ' + '.', '.') } function appendFileName (fileProperties, newText) { @@ -56,31 +54,37 @@ function prependFileName (fileProperties, newText) { return fileProperties } -function guessFileNameOnAllFilesFromArguments(){ +async function guessFileNameOnAllFilesFromArguments () { // parcourir les dossiers // parcourir les fichiers console.log('liste des fichiers', mini_arguments._) - let fileList = mini_arguments._; + let fileList = mini_arguments._ + fileList.forEach(fileName => { let structureForFile = finder.destructurateFileName(fileName) // examiner les infos exif de chaque fichier pour proposer un nouveau nom - if(!structureForFile.dateStamp){ + if (!structureForFile.dateStamp) { let foundDate = finder.findExifCreationDate(fileName) - if(foundDate){ - structureForFile.dateStamp = (finder.findExifCreationDate(fileName) + '') + console.log(' =>>>>>>> foundDate : ', foundDate) + if (foundDate) { + structureForFile.dateStamp = (finder.findExifCreationDate(fileName) + '') + + } else { + console.log(' pas de date trouvée dans le nom') } } - let newname = makeFileNameFromProperties(structureForFile) - if(fileName !== newname ){ + if (fileName !== newname) { - console.log(' nouveau nom:',newname ) - }else{ - console.log(' rien à changer' ) + console.log(' nouveau nom:', newname) + } else { + console.log(' rien à changer') } + + }) } @@ -94,6 +98,6 @@ if (enableTestsLocally) { TestFindFormattedDate() TestScreenShotIsFoundAndRenamed() } -if (reportStatistics || mini_arguments.stats) { +if (reportStatistics || mini_arguments.stats) { finder.reportStatistics() } diff --git a/rangement/testFiles/2sqdf45s5g456ghdf.jpg b/rangement/testFiles/2sqdf45s5g456ghdf.jpg new file mode 100644 index 00000000..7e387cfd Binary files /dev/null and b/rangement/testFiles/2sqdf45s5g456ghdf.jpg differ diff --git a/rangement/testFiles/received_582637990728055.webp b/rangement/testFiles/received_582637990728055.webp deleted file mode 100644 index 71eedad5..00000000 Binary files a/rangement/testFiles/received_582637990728055.webp and /dev/null differ diff --git a/rangement/testFiles/tempFileForShare_20210910-004429.jpg b/rangement/testFiles/tempFileForShare_20210910-004429.jpg deleted file mode 100755 index 10a9808b..00000000 Binary files a/rangement/testFiles/tempFileForShare_20210910-004429.jpg and /dev/null differ