As topic.
Thanks in advance
Otto
As topic.
Thanks in advance
Otto
Otto,
Via MS-DOS with command DEL and parameter /S is possible to delete all files into all sub-directories.
Or you need to create a recursive function, starting of the last sub-directory and removing all files and, after, removing the own directory... or something like this.
Julius,
thank you. I thought there is somewhere a function for this task.
Regards,
Otto
#include "Fivewin.ch"
#include "Directry.ch"
FUNCTION MAIN()
? LMKDIR( "TEST" )
? MEMOWRIT( "TEST\TEST.TXT", "This is a test" )
? DELETEDIR( "TEST" )
RETURN NIL
FUNCTION DELETEDIR( cDir )
LOCAL aDir, cName
LOCAL i
aDir = DIRECTORY( cDir + "\*.*", "HRD" )
FOR i = 1 TO LEN( aDir )
cName = aDir[ i, F_NAME ]
IF cName == "."; LOOP; ENDIF
IF cName == ".."; LOOP; ENDIF
cName = cDir + "\" + cName
IF "D" $ aDir[ i, F_ATTR ]
IF !DELETEDIR( cName )
RETURN .F.
ENDIF
ELSE
IF FERASE( cName ) = -1
? "Impossibile cancellare il file " + cName + "."
RETURN .F.
ENDIF
ENDIF
NEXT
IF !LRMDIR( cDir )
? "Impossibile cancellare la cartella " + cDir + "."
RETURN .F.
ENDIF
RETURN .T.// The example creates and deletes directories and outlines possible
// error conditions.
PROCEDURE Main
? CurDrive()+":\"+CurDir() // result: C:\xhb\tests
? MakeDir( "C:\Temp\Data" ) // result: 0
? DirRemove( "Data" ) // result: 2
? DirRemove( "C:\Temp\data" ) // result: 0
? DirRemove( "C:\temp" ) // result: 145
RETURNDirRemove() only deletes empty directories.
EMG
Thank you, Enrico,
I use your
FUNCTION DELETEDIR( cDir )
and all is working.
Thanks again,
Otto
Does exist a function that a function that allows me to copy
all files and folders even if they are empty?
IF I have this situation and I have to copy all structure the function directoryrecurse does not consider empty directories
C:\cdx\FOTO\la\ABCD>tree /A
C:.
+---altro danno
| +---sub one
| ---subtwo
+---doppio nome
+---double name empty
+---DUE
| +---cartella_vuota
| ---marco boschi
+---empty
+---name
+---nuova cartella
---UNO
Many thanks
marco
FUNCTION DELETEDIR( cDir, lRemove )
LOCAL aDir, cName
LOCAL i
DEFAULT lRemove := .T.
aDir = DIRECTORY( cDir + "\*.*", "D" )
FOR i = 1 TO LEN( aDir )
cName = aDir[ i, F_NAME ]
IF cName == "."; LOOP; ENDIF
IF cName == ".."; LOOP; ENDIF
cName = cDir + "\" + cName
IF "D" $ aDir[ i, F_ATTR ]
IF !DELETEDIR( cName )
RETURN .F.
ENDIF
ELSE
IF FERASE( cName ) = -1
? "Impossibile cancellare il file " + cName + "."
RETURN .F.
ENDIF
ENDIF
NEXT
IF lRemove
IF !REMOVEDIR( cDir )
? "Impossibile cancellare la cartella " + cDir + "."
RETURN .F.
ENDIF
ENDIF
RETURN .T.
DLL FUNCTION REMOVEDIR( cPathName AS LPSTR ) AS BOOL;
PASCAL FROM "RemoveDirectoryA" LIB "kernel32.dll"EMG,
I intend to copy all files and folders even if they are empty
deletedir is perfect!
function DeleteFolder( cFolderToDelete )
local oFs
oFs := CreateObject( "Scripting.FileSystemObject" )
if oFs:FolderExists( cFolderToDelete )
if MsgYesNo( "Delete " + cFolderToDelete + " and all its subfolders?" )
TRY
oFs:DeleteFolder( cFolderToDelete, .t. )
MsgInfo( "Deleted" )
CATCH
MsgInfo( "Failed to delete" )
END
endif
else
MsgInfo( cFolderToDelete + " does not exist" )
endif
return nilMarcoBoschi wrote:EMG,
I intend to copy all files and folders even if they are empty
deletedir is perfect!
local oFs
oFs := CreateObject( "Scripting.FileSystemObject" )
// copy all subfolders (empty also) of f:\dbf\adt\ and their contents
oFs:CopyFolder( "f:\dbf\adt\*", "f:\tempdbfs\adt\" )
// copy files only in f:\dbf\adt\
oFs:CopyFile( "f:\dbf\adt\*" , "f:\tempdbfs\adt\" )