[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[4]: Function to parse filespec
- From: Bulat Ziganshin <bulat.ziganshin@...>
- Date: Wed, 27 May 2009 15:51:26 +0400
Hello steve,
Wednesday, May 27, 2009, 3:28:06 PM, you wrote:
> Well, that's why I always use a loop myself! Bear in mind that
> backslashes have another meaning in Unix paths.
my variant. much simpler, but doesn't handle alternative separators:
-- OS-dependent directory separator
DIR_SEPARATOR = "\\"
-- Return filename directory: c:\dir\file.ext -> c:\dir
function get_dir(filename)
return (string.match (filename, "(.*)"..DIR_SEPARATOR..".+"))
end
-- Return filename without directory: c:\dir\file.ext -> file.ext
function drop_dir(filename)
return (string.match (filename, ".*"..DIR_SEPARATOR.."(.+)"))
end
-- Return extension: file.ext -> ext
-- Filename passed shouldn't contain path!
function get_ext(filename)
return string.match (filename, ".+[.](.*)") or ""
end
-- Drop extension: file.ext -> file
-- Filename passed shouldn't contain path!
function drop_ext(filename)
return string.match (filename, "(.+)[.].*") or filename
end
--
Best regards,
Bulat mailto:Bulat.Ziganshin@gmail.com