Creating a Folder/fso vs. MkDir


L

LarryP

While searching I read a long but interesting discussion of fso vs. MkDir as
a way to create a folder. Both appear to work for me, so I lean toward the
simplicity of MkDir, but two questions:

BOTH options appear to create the folder as Read Only, and I can't find
anything in help about how to turn off that feature. Is there an argument,
or a different command, to change the Read Only attribute?

MkDir is a good alternative to fso.CreateFolder; is there something
comparable for fs.FolderExists?
 
Ad

Advertisements

D

Douglas J. Steele

I can't think of any reason why either would produce Read Only folders. When
you create a folder (or file) within another folder, it should inherit
permissions from the parent folder. If the user only has Read Only access to
the parent folder, then presumably he/she wouldn't be able to create a
folder at all.

An equivalent of FolderExists is

Function FolderExists(PathToFolder As String) As Boolean
Dim strPath As String

If Right$(PathToFolder, 1) <> "\" Then
strPath = PathToFolder & "\"
Else
strPath = PathToFolder
End If

If Len(Dir(strPath, vbDirectory)) > 0 Then
FolderExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)
End If

End Function
 
L

LarryP

Hmmm -- puzzling. It's right under c:\, so I'm darned if I can see why it
should be read only. Maybe somebody else will chime in with a way to set it
to Read Only = False....

As to FolderExists, if MkDir doesn't throw an error when the folder already
exists, then that's not going to be a problem. If it does, I'll use your
code. Thanks.
 
Ad

Advertisements

D

Douglas J. Steele

You'll get an error 75 ("Path/File access error") if the folder already
exists. Of course, an alternative to using that function would be to trap
that error in your error handler, but it's cleaner to check rather than
trap.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top