Page 1 of 1 1
Topic Options
#77671 - 2001-04-26 01:56 AM MAKEPATH( ) UDF Function
Anonymous
Unregistered


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

Top
#77672 - 2001-04-26 03:40 AM Re: MAKEPATH( ) UDF Function
Anonymous
Unregistered


Or you could download the freeware MMD.exe (multi-level make directory) 32-bit command line utility from www.ScriptLogic.com

Being that it is C++ code, it is probably a bit faster than a UDF.

-Brian

Top
#77673 - 2001-04-26 06:06 PM Re: MAKEPATH( ) UDF Function
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
NT already does MMDs, try SHELL "%comspec% cmd /c MD dir1\dir2\dir3\dir4\dir5" and see what happens.

Use the TREE command from the top dir to quickly view the dirs


cj

Top
#77674 - 2001-04-26 06:11 PM Re: MAKEPATH( ) UDF Function
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
oops, double post


cj

[This message has been edited by cj (edited 26 April 2001).]

Top
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 509 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.048 seconds in which 0.02 seconds were spent on a total of 12 queries. Zlib compression enabled.