Walk a directory/Recursively: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: modified the code to work with the latest version of Sidef) |
|||
Line 1,120: | Line 1,120: | ||
#matchingfilenames</lang> |
#matchingfilenames</lang> |
||
-> array(myfile.lasso, test.lasso, rosetta.lasso) |
-> array(myfile.lasso, test.lasso, rosetta.lasso) |
||
=={{header|LiveCode}}== |
|||
This implementation only lists folders with files that match the specified pattern (use * to match all). |
|||
<lang LiveCode>function listfiles d, ext |
|||
put dirwalk(d) into fileDirList |
|||
repeat for each line fd in fileDirList |
|||
set the defaultFolder to fd |
|||
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 |
|||
filter filelist without empty |
|||
return filelist |
|||
end listfiles |
|||
function dirwalk d |
|||
set the defaultfolder to d |
|||
put the folders into dirlist |
|||
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 listfiles(the home folder & slash & "music", "*.mp*")</lang> |
|||
Output |
|||
<pre>... /Users/xxx/music/albumx/trackx.mp3 |
|||
/Users/xxx/music/albumx/trackx2.mp3 |
|||
/Users/xxx/music/albumy/tracky.mp3 ...</pre> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |