lune-org/lune

There should be a way to get the contents (files and subdirectories) of a directory

Closed this issue · 1 comments

Something like os.listdir() in Python:


import os, sys

# Open a file
path = "/var/www/html/"
dirs = os.listdir(path)

# This would print all the files and directories
for file in dirs:
   print(file)

Which would print:

stamp
faq.htm
_vti_txt
robots.txt
itemlisting
resumelisting
writing_effective_resume.htm
advertisebusiness.htm
papers
resume

You can use fs.readDir:

local fs = require("@lune/fs")

for _, entryName in fs.readDir("myDirName") do
    if fs.isFile("myDirName/" .. entryName) then
        print("Found file " .. entryName)
    elseif if fs.isDir("myDirName/" .. entryName) then
        print("Found subdirectory " .. entryName)
    end
end