Created code to walk Windows directory tree but the predicates exists_directory/1 and exists_file/1 are not working as expected in that they always return false.
test_01 :-
process_directory('C:\\Program Files\\swipl').
process_directory(Directory) :-
format('Directory: ~w~n',[Directory]),
directory_files(Directory,Files),
process_files(Files).
process_files([File|Files]) :-
process_file(File),
process_files(Files).
process_files([]).
process_file(File) :-
(
File = '.',
exists_directory(File),
format('Directory: ~w~n',[File])
;
File = '..',
exists_directory(File),
format('Directory: ~w~n',[File])
;
exists_directory(File),
process_directory(File)
;
exists_file(File),
format('File: ~w~n',[File])
;
format('Unknown: ~w~n',[File])
).
Also tried using absolute_file_name/2 but couldn’t get that to work either.
Example run:
?- test_01.
Directory: C:\Program Files\swipl
Directory: .
Directory: ..
Unknown: bin
Unknown: boot
Unknown: boot64.prc
Unknown: demo
Unknown: doc
Unknown: include
Unknown: lib
Unknown: library
Unknown: LICENSE
Unknown: README.md
Unknown: swipl-win.rc
Unknown: swipl.home
Unknown: swipl.ico
Unknown: Uninstall.exe
Unknown: xpce
true .
How is a Windows directory tree walked using SWI-Prolog?