Thread: Force relative paths

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    9

    Force relative paths

    Hi in my program there is an option to enter a directory as a command line argument. Is there any check I can perform to see whether this directory is relative to the current working directory?

    For example if we are /home/user and the user wants to input /home/user/folder they have to type ./folder.

    I need this to keep folder structure. Failing this is there anyway which I can compare two strings to produce the relative paths.

    For example I will always have the current working directory in absolute stored in 'cwd' and I will also have the absolute path of the user entered directory stored in 'folder'

    Can I compare the two and produce a relative path of 'folder' from 'cwd'?

    Thanks for your help

    Edit: This program is intended for Ubuntu Linux btw

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Absolute paths start with /

    Relative paths don't.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    9
    Cheers. Never even thought about that, been racking my brain for ages.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exec with system(..), how to use relative paths?
    By sept in forum C++ Programming
    Replies: 2
    Last Post: 08-24-2008, 01:22 PM
  2. relative paths with autotools
    By zxcv in forum Tech Board
    Replies: 1
    Last Post: 02-28-2008, 11:18 AM
  3. relative paths with XPath in libxml2
    By sparcz in forum C Programming
    Replies: 3
    Last Post: 10-12-2006, 02:49 AM
  4. boost::filesystem - relative paths
    By azteched in forum C++ Programming
    Replies: 2
    Last Post: 03-05-2005, 06:24 AM
  5. using relative file paths..?
    By anomaly in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2003, 03:36 PM