ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Command to find parent folder

Solved!
Go to solution

Hi, I am searching for a way to find the folder "above" the folder stated by DIAdem FILEDLGDIR.
So if the FILEDLGDIR is "C:\Data\Test1\Raw" I would like to get this path "C:\Data\Test1".
I guess I could search the path string from "right(FILEDLGDIR,i)" and delete everything until I find a "\" but isn't there a easier way to find the parent folder of a path?

Thanks in advance!
/Mikael

0 Kudos
Message 1 of 7
(2,415 Views)
Solution
Accepted by topic author Mike_77

Hi Mike_77,

 

That's what you need to do in the end. Here is an example:

dim sPathLong, sPathShort

sPathLong = "C:\Data\Test1\Raw"

' maake sure that the last character is "\"
sPathLong = PathAddTrailingBackslash(sPathLong)

sPathShort = left(sPathLong, InStrRev(sPathLong, "\", len(sPathLong) - 1))

msgbox sPathLong & vbCRLF & sPathShort

 

Greetings

Walter

Message 2 of 7
(2,381 Views)

Thanks, the InStrRev-command was very good!

InStrRev(sPathLong, "\", len(sPathLong) - 1)

 However, DIAdem did not like the PathAddTrailingBackslash(sPathLong)-command.

 

/Mikael

0 Kudos
Message 3 of 7
(2,375 Views)

Which DIAdem version do you have?

 

Greetings

Walter

0 Kudos
Message 4 of 7
(2,371 Views)

DIAdem 2012 at the moment but have version 2021 soon.

/Mikael

0 Kudos
Message 5 of 7
(2,365 Views)

OK, DIAdem 2012 does not support this function, but 2021 does.

 

Greetings

Walter

0 Kudos
Message 6 of 7
(2,359 Views)
Solution
Accepted by topic author Mike_77

Just use the filesystem object from VBscript:

   Option Explicit
   Dim fso,GetTheParent

   Set fso = CreateObject("Scripting.FileSystemObject")
   GetTheParent = fso.GetParentFolderName("C:\Data\Test1")

 

Message 7 of 7
(2,306 Views)