In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Delete Folder

Xailer professional forum in English
Responder
Timm
Mensajes: 136
Registrado: Lun Jun 21, 2010 11:01 am

Delete Folder

Mensaje por Timm »

Hi!

I delete folders with oFs:DeleteFolder( cFolder, .t. ) but this crashes with an error message when a file in the directory is in use (for example in Adobe Reader).

Does someone have a idea how to check if a folder can be deleted?

Best regards, Timm.
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: Delete Folder

Mensaje por ignacio »

Hi Timm,

The easiest way: Just use a TRY..CATCH

But I suggest to first read all the files on that directory and below and try to delete them one by one. If any deletion fails show a message.

Use the following function to retrieve all the files.

Regards,

Código: Seleccionar todo

STATIC FUNCTION RecurseDir( cMask, lRecursive, aFiles )

   LOCAL aDir, aFile
   LOCAL cPath, cFile

   DEFAULT aFiles TO {}, lRecursive TO .F.

   aDir  := Directory( cMask )
   cPath := FilePath( cMask )
   cMask := FileFullname( cMask )

   FOR EACH aFile IN aDir
      cFile := aFile[ F_NAME ]
      AAdd( aFiles, cPath + "\" + cFile )
   NEXT

   IF lRecursive
      aDir := Directory( cPath + "\*.*", "D" )
      FOR EACH aFile IN aDir
         cFile := aFile[ F_NAME ]
         IF "D" $ aFile[ F_ATTR ] .AND. cFile != "." .AND. cFile != ".."
            RecurseDir( cPath + "\" + cFile + "\" + cMask, .T., @aFiles )
         ENDIF
      NEXT
   ENDIF

RETURN aFiles
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Timm
Mensajes: 136
Registrado: Lun Jun 21, 2010 11:01 am

Re: Delete Folder

Mensaje por Timm »

Hi Ignacio,

many thanks for your help!
I use this now to check if a file is in use before I delete the folder:

Código: Seleccionar todo

FUNCTION IsFileOpen( cPath )

   local aFile
   local lFileOpen := .f.

   for each aFile in DirectoryRecurse( cPath + "*.*" )
      if FRename( aFile[ F_NAME ], aFile[ F_NAME ] ) <> 0
         lFileOpen := .t.
         exit
      endif
   next

RETURN lFileOpen
That gives me the possibility to inform the user before starting the deleting process.

Best regards, Timm.
Responder