lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 4/1/08, Michael Elliott <melliott42@yahoo.com> wrote:
> How can I get just the current scriptname without the
> path (hello.lua)?

I use these a lot (work on both unix and windows style pathnames):

function dirname(file_name)
	local dir = file_name:match"^(.*)[/\\][^/\\]*$"
	return dir or "."
end

function basename(file_name)
	local file = file_name:match"^.*[/\\]([^/\\]*)$"
	return file or file_name
end


Robby