OT: finding every file not in a list
Chad Perrin
perrin at apotheon.com
Thu Jan 28 10:27:39 UTC 2010
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 ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20100128/7bbc7cfe/attachment.pgp
More information about the freebsd-questions
mailing list