Created
March 19, 2020 19:50
-
-
Save bushev/d1869336d430ffd2b9f46b14f47a6926 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}`) | |
} | |
} | |
})() |
dontstoplearing
commented
Dec 20, 2023
via email
Thank you. I am sorry can you advise me how I would run something like
this? Is there something I should look up as to perform these scripts?
…On Wed, Dec 20, 2023 at 1:00 PM Yury Bushev ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hey @dontstoplearing <https://github.com/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!
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/bushev/d1869336d430ffd2b9f46b14f47a6926#gistcomment-4801978>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BE2PCUF5NROQD5NALICYHPDYKMYVFBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTAMJYHEZDGMBTU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment