This function extends the capabilities of Kixtart's MD command. Pass a path and it will create the directory and all directories along the path if they do not exist.Any comments or suggestions for improvement are welcome.
Lorne
;--------------------------------------------------------------------------
;Function: MAKEPATH()
;
;Action: Creates a directory path on a local or remote system.
;
;Syntax: MAKEPATH("path")
;
;Parameter: path - A string representing the directory path to create.
;
;Remarks: Input can be UNC or local paths. Creates all directories
; along the path if they do not already exist.
;
;Returns: 0 Path created
; -1 Invalid Path
; Error Code Function Failed
;
;Dependencies: Uses JOIN() UDF from www.scriptlogic.com
;
;Example: $path = "\\server\share\dir1\dir2\dir3"
; if not exist($path)
; $rc = MAKEPATH($path)
; if $rc = 0
; ? "Path created"
; endif
; endif
;--------------------------------------------------------------------------
function MAKEPATH($dpath)
DIM $dirs, $maxdirs, $index, $count, $rpath
$dirs = split($dpath, "\")
$maxdirs = ubound($dirs)
if instr($dpath, "\\") = 1 ; check for remote or local
$index = 4 ; path begins after '\\server\share'
else
$index = 1 ; path begins after 'drive:'
endif
select
case $maxdirs < $index
$makepath = -1 ; invalid path
case $maxdirs = $index and $dirs[$maxdirs] = ""
$makepath = -1 ; invalid path
case 1
for $count=$index to $maxdirs
$rpath = join($dirs, '\', $count)
if not exist($rpath)
md $rpath
$makepath = @error
if $makepath <> 0
exit($makepath)
endif
endif
next
endselect
endfunction