Hey monks,

I'm backing up files with chatgpt and perl. I got a pretty good utility program out of it (them, whatever). It's a utility to sort pics and convert .heic to .jpg. I happen to be looking for a particular picture I took in 2021, so this is really helpful. Typical output:

Moved and renamed: /home/fritz/Pictures/6.pics/2022-12-08-220201009.mp +4 -> /media/hogan/175F-DC61/Organized_Pics/2022/12/2022_12_08_5.mp4 Skipping: Wallpapers (not a file) Processing file: Screenshot from 2022-10-16 16-58-24.png File path: /home/fritz/Pictures/Wallpapers/Screenshot from 2022-10-16 +16-58-24.png Failed to delete original file /home/fritz/Pictures/Wallpapers/Screens +hot from 2022-10-16 16-58-24.png: No such file or directory Moved and renamed: /home/fritz/Pictures/Wallpapers/Screenshot from 202 +2-10-16 16-58-24.png -> /media/hogan/175F-DC61/Organized_Pics/2022/10 +/2022_10_16_13.png Processing complete! Number of files created: 960 fritz@laptop:~/Documents$

Source:

#!/usr/bin/perl use strict; use warnings; use File::Find; use File::Path qw(make_path); use File::Copy qw(move); use POSIX qw(strftime); # Define the source and target directories my $source_dir = '/home/fritz/Pictures'; my $target_dir = '/media/hogan/175F-DC61/Organized_Pics'; # Check if the source directory exists unless (-d $source_dir) { die "Source directory $source_dir does not exist.\n"; } # Create the target directory if it doesn't exist unless (-d $target_dir) { make_path($target_dir) or die "Failed to create target directory $ +target_dir: $!\n"; print "Created target directory: $target_dir\n"; } # Hash to store file type counts my %file_types; my $file_count = 0; # Subroutine to process each file sub process_file { if (-f $_) { my ($ext) = $_ =~ /\.([^.]+)$/; $ext = lc $ext if defined $ext; # Convert to lowercase if (defined $ext && $ext =~ /^(jpg|jpeg|png|gif|bmp|tiff|heic| +mp4)$/) { print "Processing file: $_\n"; my $file_path = $File::Find::name; print "File path: $file_path\n"; my $mod_time = (stat($file_path))[9]; my $date = strftime "%Y_%m_%d", localtime($mod_time); my ($year, $month, $day) = split('_', $date); my $dest_dir = "$target_dir/$year/$month"; unless (-d $dest_dir) { make_path($dest_dir) or die "Failed to create destinat +ion directory $dest_dir: $!\n"; print "Created destination directory: $dest_dir\n"; } my $count = 1; my $new_file_name; if ($ext eq 'heic') { $new_file_name = "${year}_${month}_${day}_$count.jpg"; while (-e "$dest_dir/$new_file_name") { $count++; $new_file_name = "${year}_${month}_${day}_$count.j +pg"; } my $converted_file_path = "$dest_dir/$new_file_name"; my $convert_command = "heif-convert $file_path $conver +ted_file_path"; system($convert_command) == 0 or die "Failed to conver +t $file_path: $!\n"; unlink $file_path or warn "Failed to delete original f +ile $file_path: $!\n"; print "Converted and moved: $file_path -> $converted_f +ile_path\n"; } else { $new_file_name = "${year}_${month}_${day}_$count.$ext" +; while (-e "$dest_dir/$new_file_name") { $count++; $new_file_name = "${year}_${month}_${day}_$count.$ +ext"; } move($file_path, "$dest_dir/$new_file_name") or die "F +ailed to move file $file_path: $!\n"; unlink $file_path or warn "Failed to delete original f +ile $file_path: $!\n"; print "Moved and renamed: $file_path -> $dest_dir/$new +_file_name\n"; } $file_count++; } else { print "Skipping file: $_ (not an image)\n"; } } else { print "Skipping: $_ (not a file)\n"; } } # Find and process files in the source directory print "Starting to process files in $source_dir...\n"; find(\&process_file, $source_dir); print "Processing complete! Number of files created: $file_count\n";

What bells and whistles might we coach it to add?

Cheers from my own private Idaho,


In reply to a nifty utility script from chatgpt by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.