Removal not empty directory
- 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
Whether there is a team of removal of the empty directory containing subdirectories and files?
			
			
									
									
						Re: Removal not empty directory
If you have Xbase tools, it contains a function named DirRemove().
			
			
									
									 The eXpress train is coming - and it has more cars.
						Re: Removal not empty directory
what is the Problem ?Eugene Lutsenko wrote:Whether there is a team of removal of the empty directory containing subdirectories and files?
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
					Last edited by Auge_Ohr on Sun Jul 29, 2012 7:15 pm, edited 1 time in total.
									
			
									greetings by OHR
Jimmy
						Jimmy
- 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
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.
									
			
									
						- 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
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:rdonnay wrote:If you have Xbase tools, it contains a function named DirRemove().
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
- 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
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
Code: Select all
PROCEDURE Main(cDir)
    ZapDir(cDir,.T.)
    RemoveDir(cDir)
RETURNgreetings by OHR
Jimmy
						Jimmy
- 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
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!!!
			
			
									
									
						

