Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

anti-tar - remove mis-extracted files and dirs

by idnopheq (Chaplain)
on Aug 29, 2001 at 23:00 UTC ( [id://108851]=CUFP: print w/replies, xml ) Need Help??

If you're like me, and I know I am, you have occasionally untarred into the wrong directory. Oh, the shame! As a metter of fact, I just did this very thing.

This little snippit cleaned out the files. The syntax is:

anti-tar tarfile

Execute it from the base directory you errantly untarred the file into. It will grab the listing of files and dirs from the tar file and remove them from the current directory and subsequent subdirs as needed. It takes advantage of rmdir's severe reluctance to blow away non-empty subdirs.

USE WITH CARE! YMMV!

#!/usr/bin/perl -w use strict; use Archive::Tar; die "Provide the name of the tar file, please!\n" unless $ARGV[0]; my $tar = Archive::Tar->new(); $tar->read( $ARGV[0], 0 ); @_ = $tar->list_files(); my @files = sort { $b cmp $a } @_; foreach ( @files ) { if ( -d ) { rmdir or warn "$_ is not empty (sharred path)\n"; next; } unlink; }

Replies are listed 'Best First'.
Re: anti-tar - remove mis-extracted files and dirs
by fundflow (Chaplain) on Aug 30, 2001 at 15:07 UTC
    This has been here before: 2711

    Your version uses the Tar module wihch is nice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://108851]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-12-03 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found