5

How to recover filepath from a given directory in C

 2 years ago
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.
neoserver,ios ssh client

How to recover filepath from a given directory in C

advertisements

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

I am trying to get all files and directories from a given directory but I can't specify what is the type (file/ directory). Nothing is being printed. What I am doing wrong and how to solve it. Here is the code: sub DoSearch { my $currNode = shift; my

How to Stream Content from a Different Directory for Subdomains

How to serve contents from different directory for virtual sub domains. Ex: http://www.website.com gets its content from www directory. for virtual.company.com i want to serve content from /www/application directory. And i want to keep the url parame

Iphone: How to display images from the document directory in Image mode?

In a App images stored in Document Directory Folder, I wanted Particular image display in Image view, How that image Display in Image View from the Document Directory ?sample code: - (NSString *)applicationDocumentsDirectory { return [NSSearchPathFor

How to recover data from a truncated table

while going though sql server interview question in book of mr. shiv prashad koirala. i got to know that, even after using truncate table command the data can be recovered. please tell me how can we recover data when data is deleted using 'delete' co

PHP Retrieve all subdirectories from a given directory

How can I get all sub-directories of a given directory without files, .(current directory) or ..(parent directory) and then use each directory in a function?you can use glob() with GLOB_ONLYDIR option or $dirs = array_filter(glob('*'), 'is_dir'); pri

How to recover data from more than one entity using a plugin, crm 2011

Hi guys how can i fetch data from more than one entity in crm 2011 using plugin. I am able to retrieve data from one entity and store it in other entity. But how can i fetch from more than one entity.The logical way would be to do a seperate retrieve

How to build notes from a given song file?

Are there any modules in Python that help us to construct or obtain the musical notes and octaves from a given original song? Thanks for the helpAs lassevk mentioned, this is a complex topic - a bit like reconstructing C code from assembly, in a way.

Asp.net (C #), How to recover data from the database?

In asp.net(c#),I use Linqtosql.. how to retrieve data from database(table) and display in textbox...?check the following links - http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx - http://www.programminghelp.com/web-deve

How to recover data from two tables whose column names are the same

How to retrieve data from two tables whose column names are the same?If you want to include rows from both tables, you can use UNION ALL: SELECT Col1, Col2, Col3 FROM Table1 UNION ALL SELECT Col1, Col2, Col3 FROM Table2

How to import resources from a given controller directory structure in Symfony2

I'm working on an application that is growing rapidly which is causing more and more controllers over time and I'm always trying to maintain good practices for do not have as many lines per controller. Right now are almost 40 controllers in Controlle

How to dynamically load python classes from a given directory?

If I define a module module with a corresponding directory of module/, can I dynamically load classes from children modules such as a.py or b.py? --module ----a.py ----b.py Does this require knowing the class name to search for? Could I setup a base

How to return a collection of files from a given directory in Elixir?

In Ruby, I can use target_files = Dir["/some/dir/path/*.rb"] #=> ["/some/dir/path/foo.rb", "/some/dir/path/bar.rb", "/some/dir/path/baz.rb"] which will return an array of all of the matching files in a directory.

how to exclude all subdirectories from a given directory in the search path of the find command in unix

I need to backup all the directory hierarchy of our servers, thus I need to list all the sub directories of some of the directories in the server. The problem is that one of those sub directories contains tens of thousands of sub directories (file wi

How to keep SVN from updating a directory already in the repository

This isn't, I don't think, a standard svn ignore question. I have a repository with a huge directory in it that I don't want. Because others using the repository do, I can't just delete it from the tree. BUT, I don't want to redownload this directory

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK