Discussions related to Visual Prolog
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Delete a group of text files

Unread post by ahmednadi »

Dear Sirs;
Good afternoon
Could you help me to delete a group of text file?
thanks
Ahmed Nady
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

I think you can puzzle this out yourself if you have some starting points in PFC:

Use the directory class to get the file names to delete:

Code: Select all

predicates     getFilesInDirectory_nd : (string Directory) -> string FullFileName nondeterm.     % @short Retrieves names of all files in the directory.     % @detail This predicate will return all existing files in the specified Directory.     % Both absolute and relative directory names, such as ".", can be used in the #Directory string.     % An empty string means current directory.     % The predicate fails if nothing is found.     % @end
Then, use the file class to delete the files:

Code: Select all

predicates     moveToRecycleBin : (string FileName).     % @short Moves file FileName to RecycleBin     % @detail When you delete a file by this predicate, the file appears     % in the Recycle Bin.     % Note: you can pass a directory name to this predicate.     % @exception nativeCallException is raised if internal API function call failed     % @end
Note that getFileInDirector_nd/1 is nondeterministic, so you can backtrack into it to get each file matching your input file mask. Also, you should implement some try/catch/finally code to handle exceptions due to a locked file, etc.

This should get you started!
User avatar
Gukalov
VIP Member
Posts: 62
Joined: 5 Oct 2011 15:16

Unread post by Gukalov »

Code: Select all

directory::forAllFiles(FullDirName, {(F) :- file::delete(F)}, "*.txt", false)
ahmednadi
Active Member
Posts: 37
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi »

Dear Sir;
I didn't use try catch finally before
if you could help by clear example for that.
Thanks
Ahmed Nady
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Re:

Unread post by Harrison Pratt »

See http://wiki.visual-prolog.com/index.php ... ch-finally
ahmednadi wrote:Dear Sir;
I didn't use try catch finally before
if you could help by clear example for that.
Thanks
Ahmed Nady
Post Reply