Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
lua file system mkdir issue — Gideros Forum

lua file system mkdir issue

louislouis Member
edited September 2012 in Game & application design
I try to create a folder use lfs in app,but the new folder not exist in system...
my test code
require "lfs"
 
lfs.mkdir("|D|cache/test")
print(result,err)
out:
nil No such file or directory

lfs.c
static int make_dir (lua_State *L) {
	const char *path = luaL_checkstring (L, 1);
	int fail;
#ifdef _WIN32
	fail = _mkdir (gpath_transform(path));
#else
	fail =  mkdir (gpath_transform(path), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
	                                      S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
#endif
	if (fail) {
		lua_pushnil (L);
        lua_pushfstring (L, "%s", strerror(errno));
		return 2;
	}
	lua_pushboolean (L, 1);
	return 1;
}

Comments

  • OK,I got it.....
    require "lfs"
     
    lfs.mkdir("|D|cache")
    print(result,err)
    This is OK.
  • techdojotechdojo Guru
    Accepted Answer
    I haven't used lfs but does the "cache" folder exist first, are you trying to create two folders at once - do you have create each branch of the tree separately?
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • are you trying to create two folders at once Yes.
    do you have create each branch of the tree separately? No.

    I found this problem,so I separate directory and mkdir folder hierarchy.
    require "lfs"
    function saveDataToFile(dir,filename,data)
    	local iter, dir_obj = pcall(lfs.dir,dir)
    	if iter==false then
    		local dir_split=str_split(dir,"/")
    		local new_folder=nil
    		for i=1,table.getn(dir_split) do
    			local v=dir_split[i]
    			if new_folder==nil then
    				new_folder=v
    			else
    				new_folder=new_folder.."/"..v
    			end
    			local mkdir_result,mkdir_err=pcall(lfs.mkdir,new_folder)
    		end
    	end
    	local out,err = io.open(dir..filename, "wb")
    	if out then
    		print("SUCC:save data to local file:"..dir..filename)
    		out:write(data)
    		out:close()
    	else
    		print("FAIL:save data to local file error:"..err)
    	end
    end
Sign In or Register to comment.