<commit_before>#!/usr/bin/perl -w

# find duplicated files in a directory by only checking the fileSize or checkSum of the file
# call: ./finddup.pl /home/h/Downloads/tmp 0 > /home/h/Downloads/tmp/sameSizes.log  2>&1

# 1. param: dir to check
# 2. param: 0 or 1 = useCheckSum off/on

use strict;
use warnings;

use 5.010; # so i can use 'state'

use Digest::MD5 qw(md5_hex);
use IO::File;

my $dir = $ARGV[0];
my $useCheckSum = $#ARGV > 0 ? ($ARGV[1] == '1') : 0;
my %fileKey2Name = ();
my $sameKeys = 0;
my $fileKey2Names = 0;

opendir(DH, $dir) or die "!open $dir";
my @files = readdir(DH);
closedir(DH);

@files = sort @files;                                   # sort alphabetically

foreach(@files)
{
    my $fn = $_;
    my $absFn = $dir . "/" . $fn;
    if (-f $absFn)                                      # = is a file
    {
        my $fileSize = -s $absFn;                       # = getFileSize, similar to stat
        my $key = $fileSize;
        $fileKey2Names = (keys %fileKey2Name);
        if ($useCheckSum)
        {
            my $checkSum = getCheckSum($absFn);
            $key = $checkSum;
        }
        
        if ($useCheckSum and (($fileKey2Names % 10) == 0))
        {
            _log(".");<commit_msg>find duplicated files by checking file sizes, in perl<commit_after>#!/usr/bin/perl -w

# find duplicated files in a directory by only checking the fileSize or checkSum of the file
# call: ./finddup.pl /home/h/Downloads/tmp 0 > /home/h/Downloads/tmp/sameSizes.log  2>&1

# 1. param: dir to check
# 2. param: 0 or 1 = useCheckSum off/on

use strict;
use warnings;

use 5.010; # so i can use 'state'

use Digest::MD5 qw(md5_hex);
use IO::File;

my $dir = $ARGV[0];
my $useCheckSum = $#ARGV > 0 ? ($ARGV[1] == '1') : 0;
my %fileKey2Name = ();
my $sameKeys = 0;
my $fileKey2Names = 0;

opendir(DH, $dir) or die "!open $dir";
my @files = readdir(DH);
closedir(DH);

@files = sort @files;                                   # sort alphabetically

foreach(@files)
{
    my $fn = $_;
    my $absFn = $dir . "/" . $fn;
    if (-f $absFn)                                      # = is a file
    {
        my $fileSize = -s $absFn;                       # = getFileSize, similar to stat
        my $key = $fileSize;
        $fileKey2Names = (keys %fileKey2Name);
        if ($useCheckSum)
        {
            my $checkSum = getCheckSum($absFn);
            $key = $checkSum;
        }
        
        if ($useCheckSum and (($fileKey2Names % 10) == 0))
        {
            _log(".");  #calculating checkSum is slow > show progress to calm down user
{'fraction_non_alphanumeric': 0.14352392065344224, 'fraction_numerical': 0.021781408012446518, 'mean_word_length': 1.9734104046242775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7343803', 'n_tokens_mistral': 944, 'n_tokens_neox': 893, 'n_words': 269}