Walk a directory/Recursively: Difference between revisions

Content added Content deleted
Line 1,360: Line 1,360:


=={{header|LiveCode}}==
=={{header|LiveCode}}==
<lang LiveCode>function recurDir dir, ext
<lang LiveCode>function pathsForPatternAndDirectory pPattern, pDirectory
set the defaultFolder to dir
set the defaultFolder to pDirectory
repeat for each line fi in the files
filter the files with pPattern
if fileExt(fi) = ext then
repeat for each line tFile in it
put the longfilepath of fi & cr after fileList
put pDirectory & slash & tFile & cr after tPaths
end if
end repeat
end repeat
repeat for each line di in the folders
filter the folders without ".."
if di is not "." and di is not ".." then
repeat for each line tFolder in it
put recurDir((dir & slash & di), ext) & cr after fileList
put pathsForPatternAndDirectory(pPattern, pDirectory & slash & tFolder) after tPaths
end if
end repeat
end repeat
filter fileList without empty
return fileList
return tPaths
end pathsForPatternAndDirectory
end recurDir

function fileExt f
set the itemdel to "."
return the last item of f
end fileExt</lang>
Example
<lang LiveCode>put recurDir(the home folder & slash & "music", "mp3")</lang>
Output
<pre>... /Users/xxx/music/albumx/trackx.mp3
/Users/xxx/music/albumx/trackx2.mp3
/Users/xxx/music/albumy/tracky.mp3 ...</pre>


=={{header|Lua}}==
=={{header|Lua}}==