Folder Deleting

Discussions related to Visual Prolog
ahmednadi
VIP Member
Posts: 84
Joined: 15 Sep 2009 14:06

Folder Deleting

Unread post by ahmednadi » 11 Apr 2015 12:14

Dear Sirs;
I hope to find all of you in good health.
Could you help me to delete a folder and its contents?
Regards;
AHMED NADY

User avatar
Thomas Linder Puls
VIP Member
Posts: 1622
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 11 Apr 2015 21:54

If you mean remove from the project but keep the files on the disk then select the folder in the project tree (in the IDE) and press the DEL key.

If you mean really delete the folder from the disk you can open the folder in an explorer (can be done from the project tree right clicking on the folder and select Explore...) and then deleting it there (also using the DEL key).
Regards Thomas Linder Puls
PDC

ahmednadi
VIP Member
Posts: 84
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi » 13 Apr 2015 9:57

Dear Sir;
Thank you for your reply.
I mean Delete that delete the folder from the disk.
I want to create a predicate to delete a selected folder to be deleted with its contents.
When I try this, error appears telling me that the folder has contents.
Therefore, I want to delete the folder with its contents whatever.
Regards;
Eng. Ahmed Nady

User avatar
Gukalov
Active Member
Posts: 27
Joined: 5 Oct 2011 15:16

Unread post by Gukalov » 13 Apr 2015 12:08

Hi.

Just remove subfolder by subfolder, file by file.

Code: Select all

class predicates     deleteFolder : (string Folder). clauses     deleteFolder(Folder) :-         foreach SubFolder = directory::getSubDirectories_nd(Folder) do             deleteFolder(SubFolder)         end foreach,         directory::forAllFiles(Folder,             {(File) :- %                file::setAttributes(File, [fileSystem_api::readOnly], false),                 file::delete(File)}),         directory::deleteDirectory(Folder).
Do not forget catch errors according your needs.

User avatar
Tonton Luc
VIP Member
Posts: 500
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 14 Apr 2015 12:21

Hi,

:idea:

Code: Select all

clauses     onTest(_Source, _MenuTag):-         mainExe::getFileName(Root,_),         if Path = directory::browseForFolder(getVpiWindow(),"Please select a folder :",Root,false) then             Stop = varM::new(0),             foreach F = directory::getFilesInDirectoryAndSub_nd(Path) do                 try                     file::delete(F)                 catch _ do                     Stop:value := 1,                     succeed()                 end try             end foreach,             if Stop:value = 0 then                 try                     directory::deleteDirectory(Path)                 catch _ do                     succeed()                 end try             else                 vpiCommonDialogs::note("Cannot delete :","this folder is not empty.")             end if         end if.

User avatar
Gukalov
Active Member
Posts: 27
Joined: 5 Oct 2011 15:16

Unread post by Gukalov » 14 Apr 2015 16:47

Bonjour.
It lacks subFolders deleting, looks like...

I use something like this:

Code: Select all

class predicates     deleteFolder : (string Folder) -> setM{string FileName} Undeleted. clauses     deleteFolder(Folder) = Set :-         Set = setM_redBlack::new(),         deleteFolder(Folder, Set).   class predicates     deleteFolder : (string Folder, setM{string FileName} Undeleted). clauses     deleteFolder(Folder, Set) :-         foreach SubFolder = directory::getSubDirectories_nd(Folder) do             deleteFolder(SubFolder, Set)         end foreach,         directory::forAllFiles(Folder,             {(File) :-                 try                     file::delete(File)                 catch _ do                     Set:insert(File)                 end try}),         try directory::deleteDirectory(Folder) catch _ do succeed() end try.
If the set:isEmpty() after calling, then deleting complete, else there are files to do what it need to do with.

Post Reply