up renaming

This commit is contained in:
Tykayn 2023-07-19 18:28:24 +02:00 committed by tykayn
parent 91a61d2c07
commit 1c1f9ed5fd
2 changed files with 28 additions and 13 deletions

View File

@ -32,7 +32,7 @@ class config_rangement {
base_archive_folder = constants.base_archive_folder
templates = mainTemplates;
statistics = {};
keepOriginalNameInRename = true;
keepOriginalNameInRename = false;
log_actions = true;
/**

View File

@ -96,9 +96,9 @@ export default class finder {
} else {
log.debug(' -------- dateStampInFileNameOriginal: ', structureForFile.dateStampInFileNameOriginal)
}
let fetchplace = cwd+'/'+structureForFile.fullPath
log.debug(' -------- trouver les infos exif', fetchplace)
this.findExifCreationDate(fetchplace)
log.debug(' -------- trouver les infos exif', structureForFile.fullPath)
this.findExifCreationDate(structureForFile.fullPath)
.then(data => {
log.info(' ... chercher la date de création : "' + structureForFile.freeText + '"')
log.debug('data', data)
@ -146,12 +146,14 @@ export default class finder {
static renameFile(originalFileName: string, fileMixedNewName: string) {
if (rangement_instance.keepOriginalNameInRename) {
log.debug(' +++++++++ on ajoute le nom original dans le free text +++++++',originalFileName )
fileMixedNewName = this.addOriginalFileNameIfMissing(originalFileName, fileMixedNewName)
log.debug(' +++++++++ nouveau nom', fileMixedNewName)
}
let self = this;
fs.rename(originalFileName, fileMixedNewName, function (err) {
log.info('name changed', fileMixedNewName)
log.info('name changed', fileMixedNewName)
if (err) {
log.info('rename ERROR: ' + err)
} else {
@ -198,10 +200,10 @@ export default class finder {
log.debug('fileProperties.dateStampExif', fileProperties.dateStampExif)
let newName = ''
+ fileProperties.dateStampExif
+ ' '
// + ' '
+ (rangement_instance.keepFreeText ? fileProperties.freeText : '')
+ tagPlace
+ fileProperties.extension
+ tagPlace.trim()
+ fileProperties.extension.trim()
if (rangement_instance.replaceUnderscoreWithSpaces) {
newName = newName.replace('_', ' ')
@ -224,14 +226,22 @@ export default class finder {
log.info(' ______ shouldWeChangeName ', structureForFile.fileNameOriginal)
let newName = this.makeFileNameFromProperties(structureForFile)
log.debug('newName', newName)
if (structureForFile.fileNameOriginal !== newName && !this.otherRenames.includes(newName)) {
if(this.otherRenames.includes(newName)){
log.debug('nouveau nom déjà présent dans les fichiers déjà renommés, on garde en état actuel')
return;
}
if (structureForFile.fileNameOriginal !== newName) {
log.info('\n ancien nom :', structureForFile.fileNameOriginal)
log.info(' nouveau nom:', newName)
if (!this.mini_arguments['dry-run']) {
this.renameFile(structureForFile.fullPath, structureForFile.folderPath + newName)
log.debug('___________ structureForFile.folderPath', structureForFile.folderPath)
log.debug('___________ newName', newName)
this.renameFile(structureForFile.fullPath,
structureForFile.folderPath + newName)
} else {
log.info('no renaming for real, this is a dry run')
finder.statistics['filesNotModified']++
@ -331,7 +341,7 @@ export default class finder {
}
static cleanSpaces(inputString: string) {
return inputString.trim().replace(/ *g/, ' ').replace(/ /, ' ')
return inputString.replace(/ *g/, ' ').replace(/ /, ' ').trim()
}
static searchAndReplaceInFileName(searchString: string, replaceString: string, fileName: string): string {
@ -422,12 +432,17 @@ export default class finder {
*/
static destructurateFileName(fullPath: string): fileDestructuration {
let [folderPath, fileNameOriginal] = this.findFolderPath(fullPath)
let dateStampInFileNameOriginal = this.findFormattedDate(fileNameOriginal)
// if path is relative, add the current working directory as full path part
if (/^\\(?!\\)/.test(fullPath)) {
fullPath = cwd + '/' + fullPath
}
return {
fullPath,
folderPath,
fileNameOriginal,
dateStampInFileNameOriginal,
dateStampInFileNameOriginal: this.findFormattedDate(fileNameOriginal),
dateStampExif: '',
freeText: this.findFileNameFreeTextPart(fileNameOriginal),
tags: this.findTagSectionInString(fileNameOriginal),