Skip to content

Instantly share code, notes, and snippets.

@bushev
Created March 19, 2020 19:50
Show Gist options
  • Save bushev/d1869336d430ffd2b9f46b14f47a6926 to your computer and use it in GitHub Desktop.
Save bushev/d1869336d430ffd2b9f46b14f47a6926 to your computer and use it in GitHub Desktop.
Remove duplicated files from Moments (Synology NAS)
// 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}`)
}
}
})()
@dontstoplearing
Copy link

Hi there, just wondering how this works, and if this still works on synology. Is there a how to, to do or run this that you can point me to?

Thank you

@bushev
Copy link
Author

bushev commented Dec 20, 2023

Hey @dontstoplearing,

A few years ago, I came up with a script for Synology Moments to parse the duplicate report and automatically remove any duplicate files from the drive. I'm not quite certain how this script would perform with the current version of Synology Moments. But, feel free to give it a shot!

@dontstoplearing
Copy link

dontstoplearing commented Dec 20, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment