How to recover filepath from a given directory in C
source link: https://www.codesd.com/item/how-to-recover-filepath-from-a-given-directory-in-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to recover filepath from a given directory in C
I'm looking for an efficient way to convert absolute filepath to a path relative to a specific directory.
Let's say we have to following structure:
D:\main\test1\blah.txt
D:\test2\foo.txt
With "D:\main"
being the reference directory, then result would be:
- blah.txt => "\test1\blah.txt"
- foo.txt => "..\test2\foo.txt"
Any clue ?
Notes for the record:
It seems that:
- there is no unified API function (cross-platform) for performing this
this question has been asked various times for other languages (though most answers take advantage of function PathRelativePathTo):
- How to get relative path from absolute path
- Getting a file path relative to a particular directory
- How do I get a relative path from one path to another in C#
You are giving windows paths in your example. So, if it is acceptable for you to use the WinAPI functions, you can use PathRelativePathTo.
Related Articles
Print files and subdirectories from a given directory
How to Stream Content from a Different Directory for Subdomains
Iphone: How to display images from the document directory in Image mode?
How to recover data from a truncated table
PHP Retrieve all subdirectories from a given directory
How to recover data from more than one entity using a plugin, crm 2011
How to build notes from a given song file?
Asp.net (C #), How to recover data from the database?
How to recover data from two tables whose column names are the same
How to import resources from a given controller directory structure in Symfony2
How to dynamically load python classes from a given directory?
How to return a collection of files from a given directory in Elixir?
how to exclude all subdirectories from a given directory in the search path of the find command in unix
How to keep SVN from updating a directory already in the repository
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK