I'm trying parse a lot of text files using Julia, and I want to loop across an array of file names instead of typing out a function call to read each of them individually. So far I have been unable to find a way to search a folder for files matching a pattern.
Is there a base library Julia function that will return all file names in a given folder, matching a given string pattern?
The equivalent function in R would be list.files()
, if that helps communicate what I want.
Search File Explorer: Open File Explorer from the taskbar or right-click on the Start menu, choose File Explorer, then select a location from the left pane to search or browse. For example, select This PC to look in all devices and drives on your computer, or select Documents to look only for files stored there.
In Julia, the equivalent to list.files()
is readdir([path])
There is no built-in directory search that I know of, but it is a one-liner:
searchdir(path,key) = filter(x->contains(x,key), readdir(path))
UPDATE: Since at least Julia v0.7, contains()
has been deprecated for occursin(substring, string)
. So the above filter would now be:
searchdir(path,key) = filter(x->occursin(key,x), readdir(path))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With