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
2010-08-27 12:06:27
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
2010-08-27 12:27:41
File.basename(Dir.getwd) will return only last folder name.
Teoulas
2010-08-27 12:45:26
@ajsie - see update.
Gishu
2010-08-27 12:52:56
+5
A:
dirname = File.basename(Dir.getwd)
File.basename()
returns the base name even when its argument is the path of a directory.
kiamlaluno
2010-08-27 12:55:32