Jump to content

Walk a directory/Recursively: Difference between revisions

m
Line 1,122:
 
=={{header|LiveCode}}==
<lang LiveCode>function listfilesrecurDir ddir, ext
This implementation only lists folders with files that match the specified pattern (use * to match all).
set the defaultFolder to dir
<lang LiveCode>function listfiles d, ext
repeat for each line fdfi in fileDirListthe files
put dirwalk(d) into fileDirList
if fileExt(fi) = ext then
repeat for each line fd in fileDirList
set put the defaultFolderlongfilepath of fi & cr toafter fdfileList
put the files into tmp
filter tmp with ext
if the number of lines of tmp > 0 then
repeat with i = 1 to the number of lines of tmp
put fd & slash before line i of tmp
end repeat
put tmp & cr after filelist
end if
end repeat
repeat for each line di in the folders
filter filelist without empty
if thedi numberis ofnot lines"." ofand tmpdi >is 0not ".." then
return filelist
put recurDir((dir & slash & di), ext) & cr after fileList
end listfiles
end if
end repeat
filter filelistfileList without empty
return filelistfileList
end recurDir
 
function dirwalkfileExt df
set the defaultfolderitemdel to d"."
putreturn the folderslast intoitem dirlistof f
end dirwalkfileExt</lang>
filter dirlist without ".*"
filter dirlist without "$*"
if the number of lines of dirlist > 0 then
repeat with i = 1 to the number of lines of dirlist
put d & slash before line i of dirlist
put dirwalk(line i of dirlist) after dirlist
end repeat
end if
return dirlist
end dirwalk</lang>
Example
<lang LiveCode>put listfilesrecurDir(the home folder & slash & "music", "*.mp*mp3")</lang>
Output
<pre>... /Users/xxx/music/albumx/trackx.mp3
Cookies help us deliver our services. By using our services, you agree to our use of cookies.