• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. splitting a pathname then moving up two directories

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 13621
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

splitting a pathname then moving up two directories

caver456
caver456 over 6 years ago

We'd like to do some file operations in a directory two levels above the readPath of a cell's directory.

cv->lib->readPath  --> /home/user/project/version/lib

we want to get '/home/user/project'

Using parseString, then chopping off the two last elements, then building the string again, would get us there; is this the best scheme?  If so, what's the most efficient way of chopping off the last two elements?  Right now we're looking at the list slice question to accomplish it which would be pretty universal but maybe not the most efficient or the least code?

  • Cancel
  • caver456
    caver456 over 6 years ago

    Hmm, looks like the least code would just be:

    strcat(cv->lib->readPath "/../..")

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 6 years ago in reply to caver456

    You could always use simplyFilename() on the result of the strcat if you want to tidy up the path a bit. An alternative would be to use pcre functions to chop off the last part - something like:

    lastBit=pcreCompile("/[^/]*/[^/]*$")
    shortened=pcreReplace(lastBit cv~>lib~>readPath "" 1)

    The simplest listy way of doing it would involve using parseString, reverse and cddr and then reversing and buildString again. Not that clean... and not so good if you have long paths or a lot of paths to do it on.

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information