Removal not empty directory

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Removal not empty directory

#1 Post by Eugene Lutsenko »

Whether there is a team of removal of the empty directory containing subdirectories and files?

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Removal not empty directory

#2 Post by rdonnay »

If you have Xbase tools, it contains a function named DirRemove().
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Removal not empty directory

#3 Post 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()
Last edited by Auge_Ohr on Sun Jul 29, 2012 7:15 pm, edited 1 time in total.
greetings by OHR
Jimmy

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Removal not empty directory

#4 Post 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.
Last edited by Eugene Lutsenko on Sat Jul 28, 2012 7:37 pm, edited 2 times in total.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Removal not empty directory

#5 Post 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

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Removal not empty directory

#6 Post 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).

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Removal not empty directory

#7 Post by Auge_Ohr »

Code: Select all

PROCEDURE Main(cDir)
    ZapDir(cDir,.T.)
    RemoveDir(cDir)
RETURN
greetings by OHR
Jimmy

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Removal not empty directory

#8 Post 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!!!

Post Reply