Excel XP & Win XP
How can I determine if a specific folder, say "C:\The Folder", exists?
I have an OP who will be sending some files, and the code to place the files
in that folder, to some people. Thanks for your time. Otto
Tim Williams - 15 Mar 2008 20:12 GMT
Dir()
Tim
> Excel XP & Win XP
> How can I determine if a specific folder, say "C:\The Folder", exists?
> I have an OP who will be sending some files, and the code to place the
> files in that folder, to some people. Thanks for your time. Otto
JLGWhiz - 15 Mar 2008 20:16 GMT
This is right out of VBA help file.
Sub ShowFolderList(folderspec)
Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.SubFolders
For Each f1 in fc
s = s & f1.name
s = s & vbCrLf
Next
MsgBox s
End Sub
If you don't want the whole list you could modifiy it to say:
For Each fl in fc
If fl.name = "ObjectFileName" Then
MsgBox "File Is There"
Else
MsgBox "Not In This Bunch"
End If
Next
> Excel XP & Win XP
> How can I determine if a specific folder, say "C:\The Folder", exists?
> I have an OP who will be sending some files, and the code to place the files
> in that folder, to some people. Thanks for your time. Otto
Dave Peterson - 15 Mar 2008 21:10 GMT
Dim TestStr as string
TestStr = ""
on error resume next
teststr = dir("c:\the folder\nul")
on error goto 0
if teststr = "" then
'doesn't exist
else
'exists
end if
==========
But maybe you don't have to check. Maybe it would be enough to just create the
folder (ignoring any error if the folder is already there):
on error resume next
mkdir "C:\the folder"
on error goto 0
> Excel XP & Win XP
> How can I determine if a specific folder, say "C:\The Folder", exists?
> I have an OP who will be sending some files, and the code to place the files
> in that folder, to some people. Thanks for your time. Otto

Signature
Dave Peterson
Otto Moehrbach - 16 Mar 2008 16:04 GMT
Dave
Thanks for that but I have to show my ignorance. It seems to me that
your code is checking for the existence of a folder "nul" as a subfolder to
the folder "the folder". If this is so then "teststr" will be "" even if
"the folder" exists, since the folder "nul" doesn't exist. Did I jump the
track somewhere? Thanks again for your time. Otto
> Dim TestStr as string
> TestStr = ""
[quoted text clipped - 23 lines]
>> files
>> in that folder, to some people. Thanks for your time. Otto
Dave Peterson - 16 Mar 2008 17:21 GMT
There are DOS devices that "exist" for every folder:
PRN (Printer)
CON (Console)
NUL (Null)
LPTx (Printer)
AUX (Auxillary)
COMx (Serial)
If the device doesn't exist, then the folder doesn't exist.
Try it and you'll see.
> Dave
> Thanks for that but I have to show my ignorance. It seems to me that
[quoted text clipped - 33 lines]
> >
> > Dave Peterson

Signature
Dave Peterson
Otto Moehrbach - 16 Mar 2008 23:15 GMT
Thanks Dave. Every time I cross paths with you I learn something. Otto
> There are DOS devices that "exist" for every folder:
>
[quoted text clipped - 48 lines]
>> >
>> > Dave Peterson
RB Smissaert - 16 Mar 2008 00:58 GMT
Function FolderExists(strFolderPath As String) As Boolean
On Error Resume Next
If Len(strFolderPath) > 0 Then
FolderExists = ((GetAttr(strFolderPath) And vbDirectory) > 0)
Err.Clear
End If
End Function
RBS
> Excel XP & Win XP
> How can I determine if a specific folder, say "C:\The Folder", exists?
> I have an OP who will be sending some files, and the code to place the
> files in that folder, to some people. Thanks for your time. Otto
Dana DeLouis - 18 Mar 2008 10:07 GMT
Just another of many...
Function IsFolder(S As String) As Boolean
IsFolder = CreateObject("Scripting.FileSystemObject").FolderExists(S)
End Function

Signature
HTH
Dana DeLouis
> Excel XP & Win XP
> How can I determine if a specific folder, say "C:\The Folder", exists?
> I have an OP who will be sending some files, and the code to place the
> files in that folder, to some people. Thanks for your time. Otto
Otto Moehrbach - 18 Mar 2008 13:05 GMT
Thanks Dana, that's short and sweet. Otto
> Just another of many...
>
[quoted text clipped - 6 lines]
>> I have an OP who will be sending some files, and the code to place the
>> files in that folder, to some people. Thanks for your time. Otto