lua-users home
lua-l archive

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


> * lfs.mkdir() only creates the directory if all parent directories are
> created first.  I prefer a directory creation function I call to do
> everything needed to fully create the directory I ask for.

based on your email, this is probably too heavyweight for you, but nonetheless:

function pathchunks(name)
	local chunks = {}
	for w in string.gmatch(name, "[^/\\]+") do
	   table.insert(chunks, 1, w)
	end
	return chunks
end

function ensurepath(path)
	local chunks = pathchunks(path)
	local originalpath = lfs.currentdir()
	lfs.chdir("/")
	for i=#chunks, 1, -1 do
		local c = chunks[i]
		local exists = lfs.attributes(c) ~= nil
		if(not exists) then
			lfs.mkdir(c)
		end
		lfs.chdir(c)
	end
	lfs.chdir(originalpath)
end


Does the job for me...
wes