Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- File System Iterator v1.0 [Updated: 14 Jan 2013]
- Copyright © 2013-2014 Joshua Asbury a.k.a. theoriginalbit [theoriginalbit@gmail.com]
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, and/or sublicense copies
- of the Software, and to permit persons to whom the Software is furnished to
- do so, subject to the following conditions:
- - The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software;
- - Visible credit is given to the original author;
- - The software is distributed in a non-profit way;
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- --]]
- local function str_contains( str, seq )
- return (str:find( seq, 1 )) ~= nil
- end
- local function contains( ignore, line )
- if type( ignore ) == "table" then
- for _, v in pairs( ignore ) do
- if line == v or str_contains( line, v ) then
- return true
- end
- end
- return false
- end
- return str_contains( line, ignore )
- end
- local function yieldFileSystem(startPath, ignorePaths, debug)
- local fsList = fs.list(startPath)
- for _, file in ipairs(fsList) do
- local path = fs.combine(startPath, file)
- if not contains(ignorePaths, path) then
- if fs.isDir(path) then
- yieldFileSystem(path, ignorePaths, debug)
- else
- coroutine.yield(path, file)
- end
- elseif debug then
- print( "Ignoring: "..path )
- end
- end
- end
- function fileSystemIter(startPath, ignorePaths, debug)
- startPath = startPath or "/"
- ignorePaths = ignorePaths or {}
- debug = debug == true
- return coroutine.wrap(function()
- yieldFileSystem(startPath, ignorePaths, debug)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement