Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Does the folder exist?

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Does the folder exist?

Dir()

Tim

"Otto Moehrbach" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Does the folder exist?

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

"Otto Moehrbach" wrote:

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Does the folder exist?

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



Otto Moehrbach wrote:

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Does the folder exist?

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


"Otto Moehrbach" wrote in message
...
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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Does the folder exist?

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
"Dave Peterson" wrote in message
...
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



Otto Moehrbach wrote:

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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Does the folder exist?

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.

Otto Moehrbach wrote:

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
"Dave Peterson" wrote in message
...
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



Otto Moehrbach wrote:

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


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Does the folder exist?

Thanks Dave. Every time I cross paths with you I learn something. Otto
"Dave Peterson" wrote in message
...
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.

Otto Moehrbach wrote:

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
"Dave Peterson" wrote in message
...
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



Otto Moehrbach wrote:

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


--

Dave Peterson



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Does the folder exist?

Just another of many...

Function IsFolder(S As String) As Boolean
IsFolder = CreateObject("Scripting.FileSystemObject").FolderE xists(S)
End Function

--
HTH
Dana DeLouis


"Otto Moehrbach" wrote in message
...
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


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Does the folder exist?

Thanks Dana, that's short and sweet. Otto
"Dana DeLouis" wrote in message
...
Just another of many...

Function IsFolder(S As String) As Boolean
IsFolder = CreateObject("Scripting.FileSystemObject").FolderE xists(S)
End Function

--
HTH
Dana DeLouis


"Otto Moehrbach" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k[_40_] Excel Programming 6 August 11th 06 08:41 PM
Create Folder If It Doesn't Exist Neutron1871 Excel Programming 4 May 6th 05 01:42 AM
Does folder exist problem Jeff Excel Programming 3 January 31st 05 03:22 PM
How to: check if folder exist, if not, create escorido[_2_] Excel Programming 2 July 9th 04 01:28 PM
How to check if a folder/directory exist using VBA wellie Excel Programming 1 March 1st 04 02:24 AM


All times are GMT +1. The time now is 03:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"