#! /usr/bin/perl -w #-------------------------------------------------------------------------- # List and optionally remove Vim swap files #-------------------------------------------------------------------------- use strict; use File::Basename; use File::Find; my @files; my $dir; # Used by find(), the real work is done here sub wanted { # We're only concerned with Vim swap files return unless /.*\.sw[mnop]/; # Store the paths for later possible deletion push @files, $File::Find::name; # Display the path and modified date print $File::Find::name . $/; my ($sec, $min, $hour, $mday, $mon, $year) = localtime((stat)[9]); print " last modified: " . sprintf("%4ld-%.2ld-%.2ld %.2ld:%.2ld:%.2ld", 1900 + $year, ++$mon, $mday, $hour, $min, $sec) . $/; } # User requested help if(@ARGV && $ARGV[0] eq "--help") { my ($basename) = fileparse $0; print <); # Remove the files if($input eq 'y') { print (unlink (@files) . " file(s) removed.$/"); } } else { print "No swap files found.$/"; }