As topic.
Thanks in advance
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
RETURN
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"
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 nil
MarcoBoschi 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\" )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: nageswaragunupudi and 99 guests