in reply to Re: delete all directories which are not in list
in thread delete all directories which are not in list

in list.name file the entries are not seperated by ,(comma) they are placed in line by line manner such as there is one entry in one line and each entry corrospond to a directory name which is actually present in directort dir1
  • Comment on Re^2: delete all directories which are not in list

Replies are listed 'Best First'.
Re^3: delete all directories which are not in list
by saskaqueer (Friar) on Feb 11, 2005 at 03:54 UTC

    Well then, maybe next time you ask a question, you will specify more details. How was I supposed to know you had one entry per line? I just assumed comma-separated because that's the closest assumption I could make out of the original posting. In any case, the code I provided will work for a one-item-per-line file anyway. But here's a refactored version of the whole thing:

    #!/usr/bin/perl -w use strict; chdir('dir1'); open(my $fh, '<', 'list.name') or die("open() failed: $!"); my %all = map { $_ => undef } grep { -d } glob("*"); delete($all{$_}) for ( map { chomp; $_ } <$fh> ); system('rm', '-ir', $_) for (keys(%all)); __END__ format of dir1/list.name: dir1 dir2 dir3 dir4 dirx