ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to determine the parent directory (https://www.excelbanter.com/excel-programming/328856-how-determine-parent-directory.html)

KS Wong[_2_]

How to determine the parent directory
 
Dear all,

I have a string variable, i.e. strDB="c:\data\aproject\database\dbfile.mdb".
I want to add a subdirectory under "c:\data\aproject\reports"
programmatically. How can I do that?

Thanks in advance!

Bob Phillips[_7_]

How to determine the parent directory
 
strDB = "c:\data\aproject\database\dbfile.mdb"
iPos = InStrRev(strDB, "\")
iPos = InStrRev(strDB, "\", iPos - 1)
MkDir Left(strDB, iPos) & "reports"


--
HTH

Bob Phillips

"KS Wong" wrote in message
...
Dear all,

I have a string variable, i.e.

strDB="c:\data\aproject\database\dbfile.mdb".
I want to add a subdirectory under "c:\data\aproject\reports"
programmatically. How can I do that?

Thanks in advance!




Jim Thomlinson[_3_]

How to determine the parent directory
 
Check out this link...

http://support.microsoft.com/default...b;en-us;213800

So use something like

Shell ("Command.com /c md C:\Test")

HTH

"KS Wong" wrote:

Dear all,

I have a string variable, i.e. strDB="c:\data\aproject\database\dbfile.mdb".
I want to add a subdirectory under "c:\data\aproject\reports"
programmatically. How can I do that?

Thanks in advance!


Jim Thomlinson[_3_]

How to determine the parent directory
 
Nice... I've been creating directories the hard way...

"Bob Phillips" wrote:

strDB = "c:\data\aproject\database\dbfile.mdb"
iPos = InStrRev(strDB, "\")
iPos = InStrRev(strDB, "\", iPos - 1)
MkDir Left(strDB, iPos) & "reports"


--
HTH

Bob Phillips

"KS Wong" wrote in message
...
Dear all,

I have a string variable, i.e.

strDB="c:\data\aproject\database\dbfile.mdb".
I want to add a subdirectory under "c:\data\aproject\reports"
programmatically. How can I do that?

Thanks in advance!





Dana DeLouis[_3_]

How to determine the parent directory
 
Here are two additional ideas:

Sub Demo1()
Dim v
Dim s As String
Const strDB = "c:\data\aproject\database\dbfile.mdb"

v = Split(strDB, Application.PathSeparator)
v(UBound(v)) = "Reports"
s = Join(v, Application.PathSeparator)
End Sub

Sub Demo2()
Dim fso
Dim s As String
Const strDB = "c:\data\aproject\database\dbfile.mdb"

Set fso = CreateObject("Scripting.FileSystemObject")
With fso
If .FileExists(strDB) Then
s = .BuildPath(.GetFile(strDB).ParentFolder.Path, "Reports")
End If
End With
End Sub

HTH :)

--
Dana DeLouis
Win XP & Office 2003


"KS Wong" wrote in message
...
Dear all,

I have a string variable, i.e.
strDB="c:\data\aproject\database\dbfile.mdb".
I want to add a subdirectory under "c:\data\aproject\reports"
programmatically. How can I do that?

Thanks in advance!




KS Wong[_2_]

How to determine the parent directory
 
Thank you very much all of you!

"Dana DeLouis" wrote:

Here are two additional ideas:

Sub Demo1()
Dim v
Dim s As String
Const strDB = "c:\data\aproject\database\dbfile.mdb"

v = Split(strDB, Application.PathSeparator)
v(UBound(v)) = "Reports"
s = Join(v, Application.PathSeparator)
End Sub

Sub Demo2()
Dim fso
Dim s As String
Const strDB = "c:\data\aproject\database\dbfile.mdb"

Set fso = CreateObject("Scripting.FileSystemObject")
With fso
If .FileExists(strDB) Then
s = .BuildPath(.GetFile(strDB).ParentFolder.Path, "Reports")
End If
End With
End Sub

HTH :)

--
Dana DeLouis
Win XP & Office 2003


"KS Wong" wrote in message
...
Dear all,

I have a string variable, i.e.
strDB="c:\data\aproject\database\dbfile.mdb".
I want to add a subdirectory under "c:\data\aproject\reports"
programmatically. How can I do that?

Thanks in advance!






All times are GMT +1. The time now is 10:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com