Search for Directories

Hi. I have this code which returns the files and directories I need but it also returns hidden files such as

“.”

“…”

“.DS_Store”

How do I exclude these?

I want to store the actual folders and the files containing within these folders.

[lua]

local lfs = require “lfs”

local doc_path = system.pathForFile( “”, system.ResourcesDirectory )

for file in lfs.dir(doc_path) do
    print("-----------------------------------------------")
    if (lfs.attributes(file,“mode”) == “file”) then
        print(“found file, “…file)
    elseif (lfs.attributes(file,“mode”)== “directory”) then
        if(file~=”.DS_Store”)then
        print(“found dir, “…file,” containing:”)

        for l in lfs.dir(file) do
             print(l)
        end
    end
    end
    print("-----------------------------------------------")
end

[/lua]

For using . Inside strings it is “%.”

I have some code that deletes all files in a given folder. I exclude the . and … folders using simple string comparison. Here is my code.

 local lfs = require( "lfs" ) local docPath = system.pathForFile( "", system.CachesDirectory ) for fileName in lfs.dir( docPath ) do if fileName ~= '.' and fileName ~= '..' then local result, reason = os.remove( system.pathForFile( fileName, system.CachesDirectory ) ) if result then --print( "Deleted file: " .. fileName ) else print( "Failed to delete file: " .. fileName .. ', reason: '.. reason ) end end end

You could do a simple string test:

if not (file:sub(1,1) == '.')  then      print(file) end

Rob

For using . Inside strings it is “%.”

I have some code that deletes all files in a given folder. I exclude the . and … folders using simple string comparison. Here is my code.

 local lfs = require( "lfs" ) local docPath = system.pathForFile( "", system.CachesDirectory ) for fileName in lfs.dir( docPath ) do if fileName ~= '.' and fileName ~= '..' then local result, reason = os.remove( system.pathForFile( fileName, system.CachesDirectory ) ) if result then --print( "Deleted file: " .. fileName ) else print( "Failed to delete file: " .. fileName .. ', reason: '.. reason ) end end end

You could do a simple string test:

if not (file:sub(1,1) == '.')  then      print(file) end

Rob