Directory name issue


#1

here is the code

dirArray = Dir.entries(".")
Dir.mkdir “SMITH, JOHN X755055”
dirArray.each do
fileentry = dirArray.pop
if fileentry.match(“txt”)
textfile = File.open(fileentry)
textfile.each_line {|line|
newdir = line.upcase.to_s
if !File.exist?(newdir)
Dir.mkdir “#{newdir}”
print "Created directory: " + newdir +
“\n”
else
print “Directory " + newdir + " already
exists…
.\n”
end
}
end
end

i have a text file in the same directory
it has two lines, they look like this:

SMITH, ADAM X755077
SMITH, ADAM X755078

when I run the above script, the first Dir.mkdir works fine
however when it reads the first line of the text file, the
Dir.mkdir “#{newdir}” doesn’t create a directory

i get this error

mkdirs.rb:9:in mkdir': Invalid argument - "SMITH, ADAM X755077" (Errno::EIN VAL) from mkdirs.rb:9 from mkdirs.rb:6:ineach_line’
from mkdirs.rb:6
from mkdirs.rb:2:in `each’
from mkdirs.rb:2

what am I doing wrong


#2
                   newdir = line.upcase.to_s

newdir = line.chomp.upcase.to_s

Your line has a linefeed. Chomp it.

Harry


#3

You can see it like this.

p line
p line.chomp

Harry


#4

Harry wrote:

                   newdir = line.upcase.to_s

newdir = line.chomp.upcase.to_s

Your line has a linefeed. Chomp it.

Harry

thanks!

i should have thought of that part of it though