Mkdir (LotusScript) Won't Create Subfolders

Hi,

I’m frustrated with the LotusScript Mkdir statement. It doesn’t function like the mkdir command of MS-DOS (or I presume any OS), namely, it won’t create all the folders requested. For example, if I do not have a “C:\Accounting” folder and I issue the following command…

mkdir "C:\Accounting\2005\January"

It will work at an MS-DOS command prompt (creating all three folders) but will bomb in LotusScript.

:soapbox=on

My gosh, if IBM/Lotus is going to provide OS command equivalents, they should function like the OS commands!

:soapbox=off

As a workaround, I tried using the Shell and Shellid statements but found that they refuse to work when fed MS-DOS commands (this is documented in Designer Help). The folder structure I need to create is supplied by the user, so I need a dynamic solution and can’t put a hardcoded MS-DOS mkdir command into a batch file that Shell/Shellid calls.

My final resort, the only workaround I can think of, is to perform some tedious text string manipulation on the path provided by the user to identify each directory and create them one at a time going from left to right.

Does anyone have any other ideas?

Thanks in Advance,

Ken

Subject: Mkdir (LotusScript) Won’t Create Subfolders

You have to create the folders one level at a time:

'Navigate to root folder first using chdir, dir

mkdir “First”

chdir “First”

mkdir “Second”

chdir “Second”

mkdir “Third”

Subject: RE: Mkdir (LotusScript) Won’t Create Subfolders

Yeah, Stan, that is what I figured. That blows!

Thanks,

Ken

Subject: RE: Mkdir (LotusScript) Won’t Create Subfolders

If memory serves (and it may not), mkdir comes directly from VB function . . . so blame MS. :o)

Anyway, here’s a little function that does what you want mkdir to do (on Win/32).

dgg

Function createPath(pstrFullPath As String) As Boolean

'// GLOBAL VARIABLES:

'//

'//

'// 02/22/2000 - Dallas Gimpel

'//

'// DESCRIPTION:

'// Given a path as input, this function will attempt to traverse the path and create the

'// necessary directory structure on the local hard drive assuming OS to be Win32.

'//

'// OUTPUT:

'// Function returns true if it is able to create the given directory structure, otherwise

'// it returns false

On Error Goto errorHandler



Const MB_ICONEXCLAMATION = 48

Const MB_OK = 0

Const ATTR_DIRECTORY = 16

Dim i As Integer

Dim strRoot As String

Dim strDirStruct As String

Dim varAllDirs As Variant



createPath = False

If Not(Instr(pstrFullPath$, ":\") = 2) Then

	Msgbox "The path could not be interpreted - unable to continue.", MB_OK + MB_ICONEXCLAMATION, "Unable to continue . . ."

	Goto functionExit

End If



strRoot$ = Left(pstrFullPath$, 1) & ":\"

If Dir$(strRoot$, ATTR_DIRECTORY) = "" Then '// the root directory is invalid

	Msgbox "The root directory is invalid - unable to continue.", MB_OK + MB_ICONEXCLAMATION, "Unable to continue . . ."

	Goto functionExit

End If



strDirStruct$ = strRoot$

varAllDirs = Split(pstrFullPath$, "\")

For i = (Lbound(varAllDirs) + 1) To Ubound(varAllDirs)

	strDirStruct$ = strDirStruct & varAllDirs(i)

	If Dir$(strDirStruct$, ATTR_DIRECTORY) = "" Then '// directory doesn't exist - create it

		Mkdir strDirStruct$

	End If

	strDirStruct$ = strDirStruct & "\"

Next i



createPath = True

functionExit:

Exit Function

errorHandler:

Msgbox "Error " & Err & ": " & Error$ & " encountered at line " & Erl & " of " & Getthreadinfo(1) & ".", , "Error encountered . . ."

Print "Error " & Err & ": " & Error$ & " encountered at line " & Erl & " of " & Getthreadinfo(1) & " . . ."

Stop

Resume functionExit

End Function

Subject: Mkdir is an old DOS command, and it’s always been this way

Subject: RE: Mkdir is an old DOS command, and it’s always been this way

Bruce,

The DOS mkdir command works perfectly, even if it hasn’t been updated since 1983. The frustratingly limited LotusScript Mkdir statement is clearly not based on the DOS version.

Ken

Subject: You’re certainly right about the newer versions of DOS; I swear that V4.x and V5.x were the way I remembered, though…

Subject: Thanks for your sample, now here’s mine

Dallas,

Thanks for your code sample. I didn’t see your post until later in the day, so I spent today coding my own version of a new and improved Mkdir.

My version differs from yours in that it…

o Doesn’t require the desired file path to start with a x:\ (where “x” is the drive letter).

o Doesn’t need to check first to see if the folder exists before issuing the Mkdir because I specify “On Error 75 Resume Next” at the top.

o Doesn’t issue messageboxes so it can be run in the background without user involvement.

o Supports Windows, Linux, and UNIX because I check for the platform before looking for the drive letter and I set a variable for the folder separator rather than hardcoding the backslash "".

o Returns users to the drive and directory where they were before the function was called.

Because I am not accessing the forum via Notes, pasting the code below is not going to look pretty, but here goes nothing! ===>

Ken

=====================================

Function makeDirectories (filePath As String) As Boolean

' This function overcomes limitations of the LotusScript Mkdir statement by being able to create multiple folders in a hierarchical structure just like the MS-DOS mkdir command.

' WARNING: This sub has only been tested in a Windows environment, but is expected to work in Linux/UNIX.  It does not support any version of Mac OS.  FYI, Mac OS X and later are based on UNIX and use a forward slash "/" separator.  Mac OS 9 and earlier use a colon ":" separator.



Dim startingDrive$, startingDir$, drive$, currentDir$, OSDirectorySeparator$



makeDirectories = False

On Error Goto Failure					' For all other errors (besides Error 75 below), handle them.

On Error 75 Resume Next			' Ignore errors associated with creating folders that already exist.

’ Set character used by the operating system to separate folders.

If isDefined("WINDOWS") Then			OSDirectorySeparator = "\"		' DOS/Windows uses a backslash.

Else

	OSDirectorySeparator = "/"		' Linux and UNIX use a forward slash.

End If



startingDrive = Curdrive		

startingDir = Curdir

’ If filePath does not end with the separator character, concatenate it. We need it for our string manipulations.

If Right(filePath, 1) <> OSDirectorySeparator Then	

	filePath = filePath & OSDirectorySeparator			 	

End If

’ If this is a Windows environment and filePath begins with a drive letter/colon, x: …

If isDefined("WINDOWS") And Instr(1, filePath, ":") = 2 Then

			drive = Left(filePath, 2)								' Extract drive letter and colon.

	Chdrive drive														' Switch to that drive.

	filePath = Strright(filePath, drive)							' Strip drive from filePath now that we've handled it.

End If

’ If filePath now begins with "" (Windows) or “/” (Linux, UNIX) …

If Instr(1, filePath, OSDirectorySeparator) = 1 Then

		Chdir OSDirectorySeparator								' Switch to this root folder.

	filePath = Strright(filePath, OSDirectorySeparator)	' Strip leading separator now that we're done with it.

End If



Do

	currentDir = Strleft(filePath, OSDirectorySeparator)

	Mkdir currentDir

	Chdir currentDir

	filePath = Strright(filePath, OSDirectorySeparator)	' Grab everything to the right of the current directory we've just processed.

	If filePath = "" Then												' If we've run out of directories to create, exit.

		Exit Do

	End If

Loop



Chdrive startingDrive		' Return user to original drive and directory.

Chdir startingDir

makeDirectories = True

Exit Function

Failure: ’ Error handling code.

makeDirectories = False

Resume Finished

Finished:

End Function

Subject: RE: Thanks for your sample, now here’s mine

Well there ya go. LotusScript has its limitations but we love it anyway, right?FYI, Java can do what you’re after independent of the OS via the mkdirs() method of java.io.File. That’s a one-liner!

Have a good weekend!

dgg