-
-
Save sadortun/487af1ded1ebee2498baaf3c6baabe57 to your computer and use it in GitHub Desktop.
Remove duplicated files from Moments (Synology NAS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Very fast-coded deduplication utility. It parses standard "Storage Analyzer" report and moves duplicated files to a separate folder. | |
// Requires "npm i csv-parse 'move-file" | |
'use strict'; | |
const path = require('path') | |
const fs = require('fs') | |
const parse = require('csv-parse/lib/sync') | |
const moveFile = require('move-file'); | |
const records = parse(fs.readFileSync('/<PATH_TO_REPORT>/duplicate_file.csv'), { | |
columns: true, | |
skip_empty_lines: true, | |
delimiter: '\t' | |
}) | |
const MOVE_TO = '/Volumes/homes/<USER_NAME>/Drive/Moments_Duplicates' | |
const groups = {}; | |
(async () => { | |
for (const record of records) { | |
if (!record.File.startsWith('/volume1/homes/<USER_NAME>/Drive/Moments')) { | |
console.log(`Skip file: ${record.File}`) | |
} | |
const realFilePath = record.File.replace('volume1', 'Volumes') | |
if (groups[record.Group]) { | |
const destination = path.join(MOVE_TO, path.basename(realFilePath)); | |
// Move file | |
console.log(`Move: "${realFilePath}" -> "${destination}"`) | |
try { | |
await moveFile(realFilePath, destination); | |
// break // <--- Uncomment to move 1 file | |
} catch (err) { | |
if (err.code !== 'ENOENT') { // already moved? | |
throw err | |
} | |
} | |
} else { | |
groups[record.Group] = true | |
console.log(`Ignore file: ${record.File}`) | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment