i want to obtain all files in a director collected in string list
["file1", "file2","file3","etc"]
-
- Posts: 14
- Joined: 13 Sep 2009 6:23
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: how to collect File Names in a specific Directory to a string List
The directory class has a number of other useful predicates in addition to this one:
Code: Select all
directory::getFilesInDirectory_nd/3->
getFilesInDirectory_nd : (
string Directory,
string WildCard,
boolean IncludeSystem)
-> string FullFilename
nondeterm.
-
- Posts: 14
- Joined: 13 Sep 2009 6:23
Re: how to collect File Names in a specific Directory to a string List
i don't want getfile Dialog to appear and select from it
i want to obain list automatically without displaying any dialog
get_dir_FileList (Directory,FilesList ):-
i don't want any dialog to appear to user
i want to obain list automatically without displaying any dialog
get_dir_FileList (Directory,FilesList ):-
i don't want any dialog to appear to user
-
- Posts: 14
- Joined: 13 Sep 2009 6:23
Re: how to collect File Names in a specific Directory to a string List
also getfile Returns a string value not List Value
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: how to collect File Names in a specific Directory to a string List
Try the code below in a console application.
The predicate getFilesInDirectory_nd/3 returns the files in the directory nondeterministically, so you need to collect them for use somehow. For your purpose I assume you want to collect them all in a list, so you can use list comprehension to collect them like this:
If you want to do something with the files stepwise and don't want to collect them in a list you can do something like this:
The predicate getFilesInDirectory_nd/3 returns the files in the directory nondeterministically, so you need to collect them for use somehow. For your purpose I assume you want to collect them all in a list, so you can use list comprehension to collect them like this:
Code: Select all
run() :-
mainExe::getFilename(AppDir, _AppNameExt),
Files = [ F || F = directory::getFilesInDirectory_nd(AppDir, "*.*", false) ],
nothing(Files),
!.
Code: Select all
run() :-
mainExe::getFilename(AppDir, _AppNameExt),
foreach F = directory::getFilesInDirectory_nd(AppDir, "*.*", false) do
stdio::write("\n", F)
end foreach,
!.
-
- Posts: 14
- Joined: 13 Sep 2009 6:23
Re: how to collect File Names in a specific Directory to a string List
Thank you very much ,
List Apprehension worked so well ,
so grateful,
List Apprehension worked so well ,
so grateful,
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: how to collect File Names in a specific Directory to a string List
I'm glad you apprehended comprehension. 
