Page 1 of 1

Removal not empty directory

Posted: Sat Jul 28, 2012 3:18 am
by Eugene Lutsenko
Whether there is a team of removal of the empty directory containing subdirectories and files?

Re: Removal not empty directory

Posted: Sat Jul 28, 2012 10:32 am
by rdonnay
If you have Xbase tools, it contains a function named DirRemove().

Re: Removal not empty directory

Posted: Sat Jul 28, 2012 2:12 pm
by Auge_Ohr
Eugene Lutsenko wrote:Whether there is a team of removal of the empty directory containing subdirectories and files?
what is the Problem ?

Code: Select all

#include "Directry.ch"
#include "common.ch"

PROCEDURE Main(cdir)
    ZapDir(cdir,.T.)
RETURN

PROCEDURE ZapDir(cDir,lRecursive)
LOCAL aFiles := Directory(cDir+"\"+"*.*","DHS")
LOCAL iMax := LEN(aFiles)
LOCAL i

DEFAULT lRecursive TO .F.

   FOR i := 1 TO iMax
      IF aFiles[ i, F_ATTR ] = "D"
         IF aFiles[ i, F_NAME ] = "." .OR. ;
            aFiles[ i, F_NAME ] = ".."
         ELSE
            ZapDir(cDir+"\"+aFiles[ i, F_NAME],lRecursive)
            RemoveDir(cDir+"\"+aFiles[ i, F_NAME])
         ENDIF
      ELSE
          FERASE(cDir+"\"+aFiles[ i, F_NAME])
      ENDIF
   NEXT

RETURN
have change Code while Xbase++ itself have Function called RemoveDir()

Re: Removal not empty directory

Posted: Sat Jul 28, 2012 7:23 pm
by Eugene Lutsenko
Thank you very much! I had a problem that I didn't apply a recursion, and itself climbed on a tree of subdirectories and since the last deleted in it files, then it, and so on to top. It turned out, but it was not pleasant to me, and this decision, certainly more beautiful and universal. I will use, there will be no yet a function deleting not an empty directory, and can be and when will appear.

Re: Removal not empty directory

Posted: Sat Jul 28, 2012 7:29 pm
by Eugene Lutsenko
rdonnay wrote:If you have Xbase tools, it contains a function named DirRemove().
I also used this function, but it turned out clumsily. Here is how at me removal not the empty folder "00000004" (in it still there is a "System" folder with a large number of different files) looked:

Code: Select all

     M_PathAppl = Path_Appl
*    MsgBox(ALLTRIM(M_PathAppl))  // D:\ALASKA\AIDOS-X\AID_DATA\00000004\System

     DIRCHANGE(M_PathAppl)        // Сделать текущей папку System, в которой находится исходное приложение

     // Определение полного имени текущей папки
     M_DiskName    := DISKNAME()
     M_CurDir      := CURDIR()
     M_DiskDir     := M_DiskName+":\"+M_CurDir
*    MsgBox(ALLTRIM(M_DiskDir))   // D:\ALASKA\AIDOS-X\AID_DATA\00000004\System

     IF M_PathAppl = M_DiskDir    // Удалось сделать папку System текущей

        FILEDELETE("*.*")         // Удалить все файлы в папке System

        // Удалить саму папку System
        DIRCHANGE(ALLTRIM(STRTRAN(M_PathAppl,"\System"," ")))
        DIRREMOVE("System")

        DIRCHANGE(M_ApplsPath)    // Удалить папку с приложением (числовое имя)
        DIRREMOVE(ALLTRIM(STRTRAN(M_PathAppl,"\System"," ")))

        // Удалить запись об удаляемом приложении в БД Appls.dbf
        DIRCHANGE(Disk_dir)
        DELETE;PACK
     ELSE
        MsgBox("Не удалось сделать папку удаляемого приложения текущей !")
     ENDIF

Re: Removal not empty directory

Posted: Sat Sep 22, 2012 2:01 pm
by Eugene Lutsenko
Dear Auge_Ohr! The program provided by you works very well, correctly and very quickly. But me it was would like, that it deleted also a directory of cDir. I tried it to make, having added before RETURN function: RemoveDir (cDir). But it works only when delete all directory, instead of subdirectories in it. Prompt, please, as it to make (that was removed not only subdirectory contents, but also she).

Re: Removal not empty directory

Posted: Sat Sep 22, 2012 3:02 pm
by Auge_Ohr

Code: Select all

PROCEDURE Main(cDir)
    ZapDir(cDir,.T.)
    RemoveDir(cDir)
RETURN

Re: Removal not empty directory

Posted: Sun Sep 23, 2012 1:06 am
by Eugene Lutsenko
I inserted RemoveDir (cDir) into the program provided by you in the end before RETURN. Everything excellently works. I was mistaken in the indication of ways: pointed a way not on closed, and to the open folder. Thanks!!!