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