Hi all,
In a database of mine I have lots of documents with one Word or Excel document as an object in each of them. Now I’m creating a lotusscript which is going to open the object, ask Word or Excel to save the Word or Excel document through VBA and at last close to object. The Word or Excel documents shall be saved in different file paths according to a field in the Notes document. The file paths often consist of several levels. If the file path exists on beforehand the script works very well. The question is what to do if it does not exist on before hand. Then the script shall create it before saving the file. I have tried something like this:
On Error Resume Next
Mkdir path
My thought was that when the script tries to make a path that allready exists it will jump over this statement and go to the next one. However, it does not create the path and so the scripts ends with an error. Can you imagine why this is so? If you can please give me som words. Thank you very much in advance.
Jo
Subject: Lotusscript does not create the path
Have you tried using Dir to test for the path? This should return “” if the path does not exist. Something like:
If Dir(path)=“” Then
Mkdir path
End If
Subject: RE: Lotusscript does not create the path
Hi Pete,
Thank you for rapid resonse. Yes, I have tried this one as well - and I’m sorry to say it doesn’t work. It gives the message: ‘Path not found’. Can it be that the mkdir command doesn’t work when several of the levels of the path do exist except the lowermost one or lowermost ones? Then mkdir shall create the part of the path which does not exist. And if this is the reason, how can I rewrite the script so that it does this rightly. Hoping to hearing from you again …
Jo
Subject: Lots of great answers in this forum if you search for mkdir
and here is a golden nugget
Subject: RE: Lots of great answers in this forum if you search for mkdir
Here’s a shorter version that works with all OS.
Sub MakeDirectory(Byval strWhere$)
' this is a more sophisticated version of the mkdir command. It tries to use
' mkdir, but if that fails because the containing directory doesn't exist, it
' calls itself recursively to create the containing directory.
On Error 76 Goto pathDoesNotExist
On Error 75 Resume Next ' folder already exists.
Mkdir strWhere
Exit Sub
pathDoesNotExist:
On Error 76 Goto fullpatherr
Dim fname$, fpath$
SplitFilepath strWhere, fpath, fname
MakeDirectory fpath
Mkdir strWhere
Exit Sub
fullpatherr:
Error Err, Strleft(Error, ": ") & ": " & strWhere
End Sub
Sub SplitFilepath(Byval fullpath$, dirpath$, filename$)
Dim ch
If Instr(fullpath, "\") Then
ch = "\"
Elseif Instr(fullpath, "/") Then
ch = "/"
Else
ch = ":" ' old Mac clients, not likely nowadays...
End If
filename = Strrightback(ch & fullpath, ch)
Dim fplen%
fplen = Len(fullpath)-Len(filename)
If fplen > 0 Then fplen = fplen - 1
dirpath = Left$(fullpath, fplen)
End Sub
Subject: Lotusscript does not create the path
If the path is levels deep you will need to check and create each level I think.
So if the path you want is “C:\dir\subdir\finaldir”
You would need to do
mkdir “C:\dir”
mkdir “C:\dir\subdir” ’ note {c:\dir} needs to exist
mkdir “C:\dir\subdir\finaldir” ’ note {c:\dir\subdir} needs to exist
You may have to split the path and loop it to get it to work.
GL
Shawn