Thread: create a folder
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default create a folder

Hi Amadee,

Whilst alternatives are good, this seems unnecessarily complex given Tom's
simple, elegant solution. Tom's code creates it if it does not exist,
ignores it otherwise, no need for folderexists!

You say FSO is the 'modern' way, it is just a later technology (which some
organisations might wish to suppress BTW) which AFAICS seeks to bring
together a number of disparate file oriented techniques. It is useful,
especially with lots of file handling functions, but IMO overkill for this
need.

And how do you come to the conclusion that OnError is chunky and creates
spaghetti code in the example supplied. It can do, but so can FSO and
anything else in the wrong hands.

And as for late-binding ... oops, you said don't go there :-). Seriously
though, as presented, the code could be either late or early binding, it
depends upon whether a reference to the type library is set.

Regards

Bob


"Amedee Van Gasse" wrote in message
...
Tom Ogilvy shared this with us in microsoft.public.excel.programming:

On Error Resume Next
Mkdir "c:\Myfolder"
On Error goto 0

Then you are sure it exists.


Or use the CreateFolder method from FileSystemObject:

Function CreateFolderDemo
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder("c:\New Folder")
CreateFolderDemo = f.Path
End Function

There is even a FolderExists method! Call this before creating your
folder.

Function ReportFolderStatus(fldr)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(fldr)) Then
msg = fldr & " exists."
Else
msg = fldr & " doesn't exist."
End If
ReportFolderStatus = msg
End Function

It's a more "modern" way of programming. On Error is rather cluncky and
created spaghetti code, FileSystemObject is really Object Oriented. But
it's not my way or the highway: please try both and use what you like
best.

(Hey, please no discussions about early/late binding. I just copied
this from some page on the MSDN DVD. Don't shoot the messenger.)

--
Amedee Van Gasse using XanaNews 1.17.3.1
If it has an "X" in the name, it must be Linux?

How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively
http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
Only ask questions with yes/no answers if you want "yes" or "no" as the
answer.
http://homepages.tesco.net/~J.deBoyn...-with-yes-or-n
o-answers.html