|
|
|
| 12 July 2002 | MakePath() |
| Author | ScriptLogic Corporation |
| Action | Creates a multi-level directory structure on a local or remote system. |
| Syntax | MakePath ( "path" ) |
| Parameters | |
| Remarks | Native alternative to using a freeware utility such as MMD.exe. Updated 7-12-2002, based on feedback from Mark Hinsch -- becuase the original version of this UDF had a dependency on the Join UDF, which is now part of KiX 4.10. |
| Returns | 0 = Path created, -1 = Invalid Path, Error Code = Function Failed. |
| Dependencies | Join() |
| Examples |
$path = "\\server\share\dir1\dir2\dir3"
IF NOT exist($path)
$rc = MakePath($path)
IF $rc = 0
? "Path created"
ENDIF
ENDIF
|
| Source |
FUNCTION MakePath ($path)
; Creates all the directories in a path.
; Returns 0 for success or error number / errorlevel
DIM $sdirs,$imaxdirs,$istartdir,$i,$srpath
$makepath=-1
$sdirs=Split($path,'\')
$imaxdirs=UBound($sdirs)
IF Left($path,2)='\\'
IF $imaxdirs < 4
EXIT -1
ELSE
$srpath='\\'+$sdirs[2]+'\'+$sdirs[3]
$istartdir=4
ENDIF
ELSE
$srpath=$sdirs[0]
$istartdir=1
ENDIF
IF ($imaxdirs < $istartdir) OR ($imaxdirs = $istartdir AND $sdirs[$imaxdirs] = '')
EXIT -1
ELSE
FOR $i = $istartdir TO $imaxdirs
$srpath=$srpath+'\'+$sdirs[$i]
IF NOT Exist($srpath)
MD "$sRPath"
IF @error
$makepath=@error
EXIT $makepath
ENDIF
ENDIF
NEXT
ENDIF
$makepath=0
ENDFUNCTION ; - MakePath -
|
|
|
|