use strict; use warnings; use Win32::API; sub FO_DELETE () { 0x03 } sub FOF_SILENT () { 0x0004 } # don't create progress/report sub FOF_NOCONFIRMATION () { 0x0010 } # Don't prompt the user. sub FOF_ALLOWUNDO () { 0x0040 } # recycle bin instead of delete sub FOF_NOERRORUI () { 0x0400 } # don't put up error UI sub Recycle { # a series of null-terminated pathnames, with a double null at the end my $paths = join "\0", @_, "\0"; my $recycle = new Win32::API('shell32', 'SHFileOperation', 'P', 'I'); my $options = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI; # for everything except paths and options, pack with Q (rather than L), since we're using 64-bit perl # my $opstruct = pack ('LLpLILLL', 0, FO_DELETE, $paths, 0, $options, 0, 0, 0); my $opstruct = pack ('QQpQIQQQ', 0, FO_DELETE, $paths, 0, $options, 0, 0, 0); return $recycle->Call($opstruct); } my $file = "C:\\Users\\James\\fish"; my $rc = Recycle($file); print "RC: $rc\n";