Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "dpath"

Title:Directory traversal module
Rating:Not rated. Create the first rating!
Latest version:0.7.3
SHA1 sum:253d3cb2af4db10407666005d3e21e06ad47b803

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
0.5.1af36a790fe1048a9936686809ca1d5c5a69400fa1https://github.com/xpxaxsxi/dpath/archive/0.5.1.zip
0.5.2f5b0cfca40d0cf74872d1590c6dad3fc81dfa14f3https://github.com/xpxaxsxi/dpath/archive/0.5.2.zip
0.5.8a461d5952ffea5deff1be647a743a63b2e4130fb6https://github.com/xpxaxsxi/dpath/archive/0.5.8.zip
0.5.10abb69dace1acf549ac15c0864c851836f5d4a3f91https://github.com/xpxaxsxi/dpath/archive/0.5.10.zip
0.5.11c8eb9904e74c2a1e67c21301605bfd76e096451518https://github.com/xpxaxsxi/dpath/archive/0.5.11.zip
0.7.2162ab344ddee56651e4d51e3bf1abf59d968882b15https://github.com/xpxaxsxi/dpath/archive/refs/tags/0.7.2.zip
0.7.3253d3cb2af4db10407666005d3e21e06ad47b8036https://github.com/xpxaxsxi/dpath/archive/0.7.3.zip

dpath

An file system traversing utility. Backtracks in the directory structure. Got inspiration from xpath/2.

This repository is under a MIT-license. The latest release version can be installed to Swi-Prolog as a pack by pack_install(dpath). There could be pre-release versions that are under development. They can be installed for example pack_install('https://github.com/xpxaxsxi/dpath/archive/0.7.2.zip')

?- file(c:/ File).
File = bootmgr ;
File = 'BOOTNXT' ;
File = 'bootTel.dat' .
?- file('file1.txt').
true.
?- file(A).
A='file1.txt';
A='file2.txt';
A='file3.pl'
?- dpath:filetype(F.pl). %Swipl doesn't like  the dot in 'F.pl' when using filetype/2 without module qualifier
                  
F=file3

Linux example:

?- dir('/'/A/B/C/D/E/F).
A = usr,
B = include,
C = 'c++',
D = '4.7',
E = ext,
F = pb_ds
?- file('/'/A/B/'smb.conf').
A = etc,
B = samba

Notes:

dpathw and wexplorer are modules that interact with Windows or Linux system utilities, that is, they can open files in a proper program using the extension. Also it is possible to open a file system browser where file is selected, both in Linux and Windows.

Filenames are not produced in alphabetical order from file/1 or filetype/2, the file system decides the order, usually the order of files is same. In other words, you can't trust that filenames are produced in same order always.

Filenames and extensions are case sensitive.

If file/1 or filetype/2 or dir/1 or some underlying predicates are cached using table predicates more speed is acquired. Caching naturally can causes problems if files are deleted or current directory is changed etc. If directory structure stays same then tabling the directory_directories/2 will give lots of speed.

Example:

Aggregated size of prolog files in current directory. Windows and Linux.

?- dpath:(A.pl=X),aggregate_all(sum(Sz),(dpath:(filetype(X),pathterm_atom(X,Path)),size_file(Path,Sz)),Res).
X = A.pl,
Res = 1349131.

Example

Number of sub-directories in current directory. Windows and Linux.

?- aggregate_all(count,dpath:dir(X),Res).
Res = 66.

Example:

Windows 10 opens up an Explorer window that has dpath.pl selected, when current directory has only one file: the dpath.pl file. If current directory has more prolog files then for each file a new Explorer windows is opened.

?- dpathw:wexplore(filetype(A.pl)).
A = dpath .

Example:

Windows 10 opens an jpg-image. Next image is shown after user hits spacebar in Swi-Prolog command prompt. All desktops are traversed while searching for images.

?- dpathw:wopen(filetype(c:/users/_/desktop/A.jpg)).

Example:

Windows 10 shows a slideshow of jpg-images from desktop-folder, every users desktop is searched

?- dpathw:wopen(filetype(c:/users/_/desktop/A.jpg)), sleep(5), fail;!.

Possible bugs: Using Swi-Prolog dicts might cause problems.

Contents of pack "dpath"

Pack contains 7 files holding a total of 23.4K bytes.