Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jan 2010 03:19:21 -0700
From:      Chad Perrin <perrin@apotheon.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: OT: finding every file not in a list
Message-ID:  <20100128101921.GA28664@guilt.hydra>
In-Reply-To: <20100128101351.GA27490@guilt.hydra>
References:  <4B6090FC.4070002@gmail.com> <20100128101351.GA27490@guilt.hydra>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Thu, Jan 28, 2010 at 03:13:51AM -0700, Chad Perrin wrote:
> 
>     losers    = Dir["#{Dir.getwd}/**/*"]
>     keepers   = IO.readlines ARGV.shift
>     startpath = ARGV.shift
> 
>     if startpath
>       Dir.chdir startpath
>     end

Oops.  Speaking of using at your own risk . . .

That line that reads `losers    = Dir["#{Dir.getwd}/**/*"]` should be
*after* the conditional block.  Thus, the above quoted code should look
like this instead:

     keepers   = IO.readlines ARGV.shift
     startpath = ARGV.shift
     
     if startpath
       Dir.chdir startpath
     end

     losers    = Dir["#{Dir.getwd}/**/*"]

. . . otherwise you might end up deleting a bunch of files in the wrong
part of the directory hierarchy if you execute the program from somewhere
other than where you want files deleted.  I guess I shouldn't have gotten
fancy and tried to provide a way to execute it from anywhere in the
filesystem.  Sorry about that.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAkthZKkACgkQ9mn/Pj01uKVngACcCdUmbu49vcWzGmAfgOmQjJR1
6+EAnAmrDaoMIRwegXXVyALzeNwRTSy6
=EjdG
-----END PGP SIGNATURE-----

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100128101921.GA28664>