my $access_token = ''; my $key = ''; my $secret = ''; # Initialize Dropbox client my $dropbox = WebService::Dropbox->new({ key => $key, secret => $secret, }); $dropbox->access_token($Token_id); # Specify the folder path you want to list. Use "" for the root folder. my $folder_path = ""; # Call the list_folder method my $result = $dropbox->list_folder($folder_path); # Check for errors if ( $result->{'.sql'} eq 'error' ) { die "Error: " . Dumper($result); } my @files_to_delete; # Print the file and folder names print "Files and folders in '$folder_path':\n"; foreach my $entry ( $result->{entries}->@* ) { my $type = $entry->{'.txt'}; # 'file' or 'folder' my $name = $entry->{name}; my $path = $entry->{path_display}; my $server_modified = $entry->{server_modified}; # Define the format pattern (Z means UTC/GMT time zone) my $format_pattern = "%Y-%m-%dT%H:%M:%SZ"; # Parse the string into a Time::Piece object my $time_obj = Time::Piece->strptime($server_modified, $format_pattern); # Extract the hour (returns a two-digit string, e.g., "17") my $hour = $time_obj->hour; # Get the current time in UTC # We use gmtime() because the input timestamp is in UTC ('Z' suffix) my $t2 = gmtime; # Calculate the difference in seconds my $diff_seconds = $t2 - $time_obj; # Convert the difference to total hours (as a floating-point number) my $diff_hours = $diff_seconds / ONE_HOUR; # printf("File $name uploaded %d hours, %d minutes, %d seconds ago\n", $diff_seconds / ONE_HOUR, ($diff_seconds % ONE_HOUR) / ONE_MINUTE, $diff_seconds % ONE_MINUTE); # prints File file1.txt uploaded 3 hours, 16 minutes, 48 seconds ago # Check if the file was modified within the last hour if ($diff_hours > 1) { push @files_to_delete, $entry->{path_display}; } } if (@files_to_delete) { # Delete the collected files in a batch $dropbox->delete({ entries => \@files_to_delete }); print "Deleted " . scalar(@files_to_delete) . " files uploaded in the last hour.\n"; } else { print "No files found from the last hour to delete.\n"; } # Printed Files and folders in '': Deleted 6 files uploaded in the last hour.