473,396 Members | 1,853 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,396 software developers and data experts.

Existing directory

If I want to decide if a file exists I can use 'if
dir("c:\test1\test2\testfile.txt")="testfile.txt"' .

But now I want my application to decide if a directory exists and, if not,
create it. Maybe there's a hard way with an error handler searching for
error codes but is there a simplier way?

/ Bo
Jul 17 '05 #1
1 2647
On Sun, 21 Nov 2004 09:29:08 GMT, "Bo Wisén" <bo*****@telia.com>
wrote:
If I want to decide if a file exists I can use 'if
dir("c:\test1\test2\testfile.txt")="testfile.txt" '.
No you don't - that is horrible
- and very likely to give you problems
But now I want my application to decide if a directory exists and, if not,
create it. Maybe there's a hard way with an error handler searching for
error codes but is there a simplier way?


You'll find what you need in here

' ---
Function FileExists(Fle$) As Boolean
Dim Q%
On Error Resume Next
Q = GetAttr(Fle$)
If Err = 0 Then
If (Q And vbDirectory) = 0 Then
FileExists = True
End If
End If
Err.Clear
End Function

' ---
Function DirExists(ADir$) As Boolean
Dim Q%
On Error Resume Next
Q = GetAttr(ADir$)
If Err = 0 Then
If (Q And vbDirectory) = vbDirectory Then
DirExists = True
End If
End If
Err.Clear
End Function
'
################################################## #######################
'
' C:\DEV\USLIB\USLIB.BAS --> X:\DEV\USLIB
'
Function ExtractFilePath$(Fle$)

Dim L9%

For L9 = Len(Fle$) To 1 Step -1
If InStr(":\", Mid$(Fle$, L9, 1)) Then
If Mid$(Fle$, L9, 1) = "\" Then
ExtractFilePath$ = Left$(Fle$, L9 - 1)
End If
If Mid$(Fle$, L9, 1) = ":" Then
ExtractFilePath$ = Left$(Fle$, L9)
End If
L9 = 1
End If
Next

End Function
Sub MakeDir(FileSpec$, Erm$)
Dim S$

Erm$ = ""
If InStr(FileSpec$, "\") Then
S$ = ExtractFilePath(FileSpec$)
Call MakeDir(S$, Erm$)
If Len(Erm$) = 0 Then
If DirExists(FileSpec$) = False Then
On Error Resume Next
MkDir FileSpec$
If Err Then Erm$ = "Error Making " + FileSpec$
On Error GoTo 0
End If
End If
End If
End Sub
Private Sub Command2_Click()
Dim Erm$, FileSpec$
' note the deliberate error
FileSpec$ = "c:\t/test\test1\test2"
Call MakeDir(FileSpec$, Erm$)
MsgBox Erm$
End Sub

Jul 17 '05 #2

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

Similar topics

3
by: Derek Fountain | last post by:
Is it possible to install a second version of an existing package? My SUSE Linux box has PIL-1.1.3 installed, and this is used by the OS for various tasks. It's bundled as part of a...
1
by: Jon Paugh | last post by:
Hi Friendly Newsgroup Readers, I switched to another PC and pulled all my source code for my solution to my new PC, after first dutifully adding my web project directories as appropriately named...
1
by: Camel Software | last post by:
I've posted this in other places, but didn't get an answer. The project I'm working on is C#, so perhaps this is an okay place to post this. If there's a more appropriate newsgroup, I'm open to it....
6
by: Jerry Higgins | last post by:
In Interdev 6.0 you can connect to an existing web. I've looked through the help and I haven't found a way to do it. Any ideas? Thanks, Jerry
2
by: ed d | last post by:
Hi, When I try to create a new web project, or "add existing project from web" or "open from source control" i'm prompted for a URL and type in a virtual directory. -- with "add project...
3
by: dave | last post by:
I need to add additional .aspx pages to an existing web site. I was hoping to create a new web project in VS 2003, build the project, copy the .aspx files and the .dll into the virtual directory...
0
by: Olivier Matrot | last post by:
Hello all, I'm looking for an existing implementation of an Active Directory Profile Provider. It could be using proprietary schema extension for storing data or an existing attribute (info for...
2
by: Paul | last post by:
I am moving an existing app written years ago to a new server. It uses Sigma Template 1.3 and Quickform 1.1.1 and PEAR.php,v 1.1.1.1 2004/02/16 The directory structure is like this: /site...
2
by: Ale | last post by:
Hi all, this is my first post here and I'm totally new at DB2 databasesand all related matters but I need help in connecting a DB2 database. I need to import data from a DB2 database to a MSSQL...
5
by: mvelasquez | last post by:
I'm working with crystal reports in my windows app. I have a pre-existing report that I will access dynamically in the application at run time. I set the parameters of the report through the...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.