FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


Delete a group of text files

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog
View previous topic :: View next topic  
Author Message
ahmednadi




Joined: 15 Sep 2009
Posts: 197

PostPosted: 27 May 2017 12:49    Post subject: Delete a group of text files Reply with quote

Dear Sirs;
Good afternoon
Could you help me to delete a group of text file?
thanks
Ahmed Nady
Back to top
View user's profile Send private message
Harrison Pratt



Des Moines, Iowa USA
Joined: 05 Nov 2000
Posts: 303

PostPosted: 27 May 2017 14:08    Post subject: Reply with quote

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:

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:

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!
Back to top
View user's profile Send private message
Gukalov



Orthez, France
Joined: 05 Oct 2011
Posts: 22

PostPosted: 27 May 2017 20:44    Post subject: Reply with quote

directory::forAllFiles(FullDirName, {(F) :- file::delete(F)}, "*.txt", false)


_________________
aagukalov@gmail.com
Back to top
View user's profile Send private message
ahmednadi




Joined: 15 Sep 2009
Posts: 197

PostPosted: 27 May 2017 21:09    Post subject: Reply with quote

Dear Sir;
I didn't use try catch finally before
if you could help by clear example for that.
Thanks
Ahmed Nady
Back to top
View user's profile Send private message
Harrison Pratt



Des Moines, Iowa USA
Joined: 05 Nov 2000
Posts: 303

PostPosted: 28 May 2017 4:29    Post subject: Re: Reply with quote

See http://wiki.visual-prolog.com/index.php?title=Language_Reference/Terms/Try-catch-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

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum