From: "Michael T. Richter" Date: 2007-06-09T13:13:36+09:00 Subject: Re: Newb Wants to Better His File, Dir code --=-tSX/Qoz8l9CJkHs1tPCh Content-Type: multipart/alternative; boundary="=-dwBwoKRgwHiZAKiRzqDS" --=-dwBwoKRgwHiZAKiRzqDS Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sat, 2007-09-06 at 12:42 +0900, Dan Zwell wrote: > > dirs =3D Dir.entries(".").reject{|e| /\.{1,2}/ =3D~ e}.find_all= {|e| > > File.directory? e} > The above has a small bug: it rejects all hidden directories. If you=20 > want to block only ".." and ".", then change it to: > dirs =3D Dir.entries(".").reject{|e| /\.{1,2}$/ =3D~ e}.find_all{|e| > File.directory? e} Ah. That is true. I tested it in a directory that didn't have hidden files or directories, so didn't note that. --=20 Michael T. Richter (GoogleTalk: ttmrichter@gmail.com) Never, ever, ever let systems-level engineers do human interaction design unless they have displayed a proven secondary talent in that area. Their opinion of what represents good human-computer interaction tends to be a bit off-track. (Bruce Tognazzini) --=-dwBwoKRgwHiZAKiRzqDS Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, 2007-09-06 at 12:42 +0900, Dan Zwell wrote:
>         dirs =3D Dir.entries(".").re=
ject{|e| /\.{1,2}/ =3D~ e}.find_all{|e|
>         File.directory? e}

The above has a small bug: it rejects all hidden di=
rectories. If you 
want to block only ".." and "."=
, then change it to:

	dirs =3D Dir.entries(".").reject{|e| /\.=
{1,2}$/ =3D~ e}.find_all{|e|
		File.directory? e}

Ah.  That is true.  I tested it in a directory that didn't have h= idden files or directories, so didn't note that.

--
Michael T. Richter <ttmri= chter@gmail.com> (GoogleTalk: ttmrichter@gmail.com)
Never, ever, ever let systems-level engineers do human interaction desig= n unless they have displayed a proven secondary talent in that area. Their = opinion of what represents good human-computer interaction tends to be a bi= t off-track. (Bruce Tognazzini)
--=-dwBwoKRgwHiZAKiRzqDS-- --=-tSX/Qoz8l9CJkHs1tPCh Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQBGaijjLqyWkKVQ54QRAo4GAKDVIn1JYIf2OPYIIF8LQGCsuJCpzgCbBjcP +Rn7RIEjuanZuTDU/H9U6Ps= =m1hq -----END PGP SIGNATURE----- --=-tSX/Qoz8l9CJkHs1tPCh--