Otto wrote: Hi,Thank You, I will try!
The recurring problem with lMkDir() – that it doesn't support recursive directory creation – has cost many of us time and nerves over the years, especially when trying to dynamically create paths with multiple intermediate folders.
Perhaps we could even maintain a small `x_compat.prg` library together – for commonly used functions such as:
StrTokenize()
DirSepDel()
FileOrDirExists()
MkDirRecursive()
Please test and improve.
Best regards,
Otto
#include "fivewin.ch" /* This is a complete, xHarbour-compatible recursive MkDirRecursive() function, without any hb_ dependencies. It includes the helper functions DirSepDel() and DirSepToOS(). Recommended: maintain a shared hbcompat.prg utility library for frequently used functions like: - StrTokenize() - DirSepDel() - FileOrDirExists() - MkDirRecursive() */ func main MkDirRecursive( "c:\SISTEMAS\SCANDOC\EMPRESA01\202505" ) return FUNCTION MkDirRecursive( cPath ) LOCAL aParts := {} LOCAL cPart := "" LOCAL i, cSep, cCurrent := "" // Normalize the path cPath := DirSepToOS( DirSepDel( cPath ) ) cSep := IF( "WINDOWS" $ Upper( OS() ), "\", "/" ) // Split path into parts aParts := StrTokenize( cPath, cSep ) // Handle absolute paths like "C:" IF ":" $ aParts[1] cCurrent := aParts[1] + cSep i := 2 ELSE cCurrent := aParts[1] i := 2 ENDIF FOR i := i TO Len( aParts ) cPart := aParts[i] IF !Empty( cPart ) cCurrent += cPart IF !FileOrDirExists( cCurrent ) MakeDir( cCurrent ) ENDIF ENDIF cCurrent += cSep NEXT RETURN .T. FUNCTION IsWindows() RETURN Upper( OS() ) $ "WINDOWS" FUNCTION DirSepDel( cPath ) IF !Empty( cPath ) .AND. Right( cPath, 1 ) $ [ "\", "/" ] RETURN Left( cPath, Len( cPath ) - 1 ) ENDIF RETURN cPath FUNCTION DirSepToOS( cPath ) LOCAL cSep := IF( OS() == "WINDOWS", "\", "/" ) RETURN StrTran( cPath, "/", cSep ) FUNCTION StrTokenize( cString, cDelim ) LOCAL aResult := {}, nPos := 1, nAt := 0 DO WHILE .T. nAt := At( cDelim, SubStr( cString, nPos ) ) IF nAt == 0 AAdd( aResult, SubStr( cString, nPos ) ) EXIT ENDIF AAdd( aResult, SubStr( cString, nPos, nAt - 1 ) ) nPos += nAt ENDDO RETURN aResult FUNCTION FileOrDirExists( cPath ) LOCAL h IF lIsDir( cPath ) RETURN .T. ENDIF h := FOpen( cPath ) IF h != -1 FClose( h ) RETURN .T. ENDIF RETURN .F.