luaext.lua

changeset 44
5700ebe9277b
parent 35
2f927eae429b
--- a/luaext.lua	Sun Aug 06 21:12:43 2023 +0300
+++ b/luaext.lua	Fri Jan 24 13:27:45 2025 +0100
@@ -89,13 +89,18 @@
     end
 end
 
+function ensure_dir_of(name)
+    local dn = path.dirname(name)
+    if dn ~= "" and not lfs.attributes(dn) then
+        ensure_dir_of(dn)
+        print("Creating directory", dn)
+        lfs.mkdir(dn)
+    end
+end
+
 function io.openX(file, mode)
     if mode=='w' then
-        local dn = path.dirname(file)
-        if not lfs.attributes(dn) then
-            print("Ensure directory", dn)
-            lfs.mkdir(dn)
-        end
+        ensure_dir_of(file)
     end
     local f, err = io.open(file, mode)
     if not f then

mercurial