--cNdxnHkX5QqsyA0e
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Aug 05, 2004 at 09:46:53AM +0900, Matthew Margolis wrote:
> I am trying to figure out how to open up a text file in a subdirectory 
> of my programs main directory.  The file I want is in the subdirectory 
> labeled text.  I get a "Permission  denied - text/" message when 
> attempting to run the code found below.
> 
> campershash = Hash.new
> Dir.entries("text").each do |textfilename|
>   campershash["#{textfilename.chop.chop.chop.chop}"] = 
> File.open("text/" + "#{textfilename}") { |f| f.gets(nil) }
> end
> 
> The Dir.entries call works finer but on the next line when I go to open 
> up each text file in the text directory I run into problems.  I am 
> running the program on windows XP with administrator privileges so I am 
> unclear as to why I am having permission issues.
> 

You're probably trying to open a directory (. and .. in 'text/'). Try
one of the two examples below:

campershash = {}
Dir.entries("text").each do |textfilename|
    # Don't know why you're using four chop's - but I've replaced them
    # with 'strip' to make the example more readable.
    campershash[textfilename.strip] = 
        File.read(File.join("text", textfilename)) if File.file?(textfilename)
end

or

campershash = {}
Dir["text/*"].each do |f|
    campershash[f.strip] = File.read(f)
end

//Anders


-- 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. Anders Engströí         aengstrom / gnejs.net
. http://www.gnejs.net    PGP-Key: ED010E7F
. [Your mind is like an umbrella. It doesn't work unless you open it.]  


--cNdxnHkX5QqsyA0e
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBEbyquNLLbe0BDn8RAnuaAJ9KdNz4zh54+MhrfA0daweNtZhomgCgj2eX
3yWy8dQW5YFabVrunVTsk1YS3
-----END PGP SIGNATURE-----

--cNdxnHkX5QqsyA0e--