![]() |
|
#1
|
|||
|
|||
|
Get Parent Directory?
Hi, I have a question about how to get the parent directory of a path. Say I have a path: C:\Dir1\Dir2\Dir3\ Is there a function that allow me to set the current directory as: C:\Dir1\Dir2\ Any help will be appreciated. Yi |
|
#2
|
|||
|
|||
|
Re: Get Parent Directory?
Yi Zhang wrote in message <38BC2EFE.A12E7927@dataviz.com>... >Hi, > >I have a question about how to get the parent directory of a path. Say I > >have a path: > >C:\Dir1\Dir2\Dir3\ > >Is there a function that allow me to set the current directory as: > >C:\Dir1\Dir2\ There is no built-in function that does this; but here's the code for a script-defined function: function GetParentDir ( szDir, svParentDir ) LIST listDirTree; NUMBER nListGetString; STRING svString; begin StrRemoveLastSlash ( szDir ); listDirTree = ListCreate ( STRINGLIST ); StrGetTokens ( listDirTree , szDir , "\\" ); if (ListCount ( listDirTree ) <= 1) then svParentDir = szDir; else ListSetIndex ( listDirTree , LISTLAST ); ListDeleteString ( listDirTree ); ListGetFirstString ( listDirTree , svString ); svParentDir = svString; nListGetString = ListGetNextString ( listDirTree , svString ); while (nListGetString = 0) svParentDir = svParentDir ^ svString; nListGetString = ListGetNextString ( listDirTree , svString ); endwhile; endif; return 0; end; -- Mark InstallShield Software Corporation |
|
#3
|
|||
|
|||
|
re:Get Parent Directory?
Mark, Thank you so much. It worked perfectly! Yi Mark at IS wrote: > Yi Zhang wrote in message <38BC2EFE.A12E7927@dataviz.com>... > >Hi, > > > >I have a question about how to get the parent directory of a path. Say I > > > >have a path: > > > >C:\Dir1\Dir2\Dir3\ > > > >Is there a function that allow me to set the current directory as: > > > >C:\Dir1\Dir2\ > > There is no built-in function that does this; but here's the code > for a script-defined function: > > function GetParentDir ( szDir, svParentDir ) > LIST listDirTree; > NUMBER nListGetString; > STRING svString; > begin > StrRemoveLastSlash ( szDir ); > listDirTree = ListCreate ( STRINGLIST ); > StrGetTokens ( listDirTree , szDir , "\\" ); > if (ListCount ( listDirTree ) <= 1) then > svParentDir = szDir; > else > ListSetIndex ( listDirTree , LISTLAST ); > ListDeleteString ( listDirTree ); > ListGetFirstString ( listDirTree , svString ); > svParentDir = svString; > nListGetString = ListGetNextString ( listDirTree , svString ); > while (nListGetString = 0) > svParentDir = svParentDir ^ svString; > nListGetString = ListGetNextString ( listDirTree , svString ); > endwhile; > endif; > return 0; > end; > > -- > Mark > InstallShield Software Corporation |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|