interstar
interstar

Reputation: 27186

Accessing and crawling the file-system in SWI-Prolog

How do I interact with the file system in SWI-Prolog?

I want to do something like this. Write some predicates which match files (either names, or open them up and match contents). But then use Prolog to drive this system so I can do queries and make inferences across the whole thing.

I'm assuming I either need to slurp data about the whole file tree in, in advance. Or I can dynamically generate a "crawl" through the file system inside some recursive predicates.

But I can't find any examples or tutorials that do more than just open, close, read and write a single file.

Upvotes: 2

Views: 139

Answers (1)

CapelliC
CapelliC

Reputation: 60024

Recently a nice predicate has been introduced, directory_member/3. It's exactly what you need to make queries about the file structure:

?- directory_member('/home/carlo/swipl-devel',Entry,[recursive(true)]).
Entry = '/home/carlo/swipl-devel/INSTALL' ;
Entry = '/home/carlo/swipl-devel/bench' ;
...

Upvotes: 2

Related Questions