Add entry count to directories

This commit is contained in:
SolitudeSF 2024-08-19 16:51:44 +03:00
parent 907ac09e34
commit f2f5e4c814
No known key found for this signature in database
GPG key ID: 789B06817C385387

View file

@ -42,6 +42,14 @@ impl File {
IconCache::Icon(cached) => Some(Icon::cast(lua, cached)).transpose(), IconCache::Icon(cached) => Some(Icon::cast(lua, cached)).transpose(),
} }
}); });
reg.add_method("count", |_, me, ()| {
if me.as_ref().cha.is_dir() {
return Ok(Some(std::fs::read_dir::<&std::path::Path>(me.as_ref().url.as_ref())?.count()));
} else {
return Ok(None);
}
});
} }
pub fn install(lua: &Lua) -> mlua::Result<()> { pub fn install(lua: &Lua) -> mlua::Result<()> {