Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for files in a folder

Tags:

julia

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.

like image 666
MDe Avatar asked Dec 10 '13 01:12

MDe


People also ask

How do I search files for a file?

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.


1 Answers

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)) 
like image 100
Isaiah Norton Avatar answered Sep 20 '22 02:09

Isaiah Norton