tags:

views:

54

answers:

2

Is there a simple way to get the name of the current folder name or do I have to do it with regexp?

+2  A: 
irb(main):001:0> Dir.getwd
=> "C:/Documents and Settings/UserName"

or did I misunderstand your question ?

Update: Try one of the below

File.split(Dir.getwd)[-1]
Pathname.new(Dir.getwd).basename.to_s
Gishu
Yeah I want to have only the current folder name, not folder path. In this case: UserName. Is there a way to do this in Ruby or do you have to use regexp?
never_had_a_name
File.basename(Dir.getwd) will return only last folder name.
Teoulas
@ajsie - see update.
Gishu
+5  A: 
dirname = File.basename(Dir.getwd)

File.basename() returns the base name even when its argument is the path of a directory.

kiamlaluno
+1 It's a bit misleading though w.r.t. readability
Gishu