473,388 Members | 979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to determine if directory exists

TTD
Hello,

I need to create a directory in code, but when de directory already exists,
I get err.number 75.

Since the creation already is in the part where a former error is sent, I
can't catch this error.

In VB there is this code
path = "C:\temp\"
If Directory.Exists(path) = False Then
' Create the directory.
Directory.CreateDirectory(path)
End If

Is there a way to determine if C:\temp already exists before I create one?

Thanks for your time.
Nov 13 '05 #1
6 14437
Rog
if len(dir(path)) = 0 then
'create the directory
end if

Nov 13 '05 #2
Might be good to use the vbDirectory argument of Dir():

Public Function FolderExists(varPath As Variant) As Boolean
On Error Resume Next
If Len(varPath) > 0 Then
FolderExists = (Len(Dir$(varPath, vbDirectory)) > 0&)
End If
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Rog" <ro************@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
if len(dir(path)) = 0 then
'create the directory
end if

Nov 13 '05 #3
Tried that as well. Sorry!

Dawn
"TTD" <tt*@hotmail.com> wrote in message
news:42*********************@diablo.nl.easynet.net ...
Hello,

I need to create a directory in code, but when de directory already
exists,
I get err.number 75.

Since the creation already is in the part where a former error is sent, I
can't catch this error.

In VB there is this code
path = "C:\temp\"
If Directory.Exists(path) = False Then
' Create the directory.
Directory.CreateDirectory(path)
End If

Is there a way to determine if C:\temp already exists before I create one?

Thanks for your time.

Nov 13 '05 #4
Allen Browne wrote:
Might be good to use the vbDirectory argument of Dir():

Public Function FolderExists(varPath As Variant) As Boolean
On Error Resume Next
If Len(varPath) > 0 Then
FolderExists = (Len(Dir$(varPath, vbDirectory)) > 0&)
End If
End Function


Another method I've used in the past (Before BASIC could find
direcrtories) is to append \nul [1] to the path as the nul device exists
in any valid path.

[1] Note in an OS nul is spelt with a single l, not "null" as in Access'

--
[OO=00=OO]
Nov 13 '05 #5
Trevor Best wrote:
Allen Browne wrote:
Might be good to use the vbDirectory argument of Dir():

Public Function FolderExists(varPath As Variant) As Boolean
On Error Resume Next
If Len(varPath) > 0 Then
FolderExists = (Len(Dir$(varPath, vbDirectory)) > 0&)
End If
End Function


Another method I've used in the past (Before BASIC could find
direcrtories) is to append \nul [1] to the path as the nul device exists
in any valid path.

[1] Note in an OS nul is spelt with a single l, not "null" as in Access'


Actually, this may be the safer option, as vbDirectory will find files
as well as directories, you could very well find a file that you thought
was a directory.

--
[OO=00=OO]
Nov 13 '05 #6
dim bExists as boolean

bExists = FileExistsDir("path")

if bExist = False
'create directory
end if
Function FileExistsDIR(sFile As String) As Boolean
FileExistsDIR = True
If Dir$(sFile) = vbNullString Then FileExistsDIR = False
End Function

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pgar | last post by:
I have a page that I have the users uploading files from their local machines. I take these files strip off their path and redirect it to a new file on the web server. I have a virtual directory...
1
by: Steven J. Reed | last post by:
I am trying to find out is a folder exists within a share on a server. I can successfully determine if a file exists within the share, but I can't figure out how to determine if it's parent folder...
4
by: css | last post by:
When I call Directory.Exists for a UNC path like below... if (Directory.Exists(@\\SomeServer\C) == false) { .... } and that server does not exist on the connected network, it takes around a...
1
by: Phil Barber | last post by:
using ASP.NET 1.1 int PID=(int)Session; string FilePath=PF.GetProjectPath(PID); if(!Directory.Exists(FilePath)) Directory.CreateDirectory(FilePath); the Directory.Exists always returns false...
2
by: CCLeasing | last post by:
If (Directory.Exists(@"c:\indigo\" + txtOfficial + @"\" + comOffice.Text + @"\" + numTerm.Value.ToString())) { storereport(); } else { Directory.CreateDirectory(@"c:\indigo\" + txtOfficial +...
5
by: Santel | last post by:
Hi, If I use Directory.Exists("C://Documents and Settings//username// Testing); it always returns false. But the directory is existing in the specified folder. It is not searching any folders...
1
by: ElenaB | last post by:
Hi, I have an application that needs to create and copy files in multiple locations that can be share folder on the network. I'm using System.IO.Directory.Exists() method to determine if...
9
by: shughes | last post by:
i am not really a programmer, so i have a question on the system.io.directory.exists what i am trying to do is have a button, once this button is clicked it checks to see if the Directory...
4
by: ndedhia1 | last post by:
Hi. I am writing a java program in which I want to ftp a file to another unix box. First I have to check if the directory exists in which I am ftping into and if it does not exist, I have to create...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.