Relative and absolute file names

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Relative and absolute file names

Post by AriSilva »

Is there a function to convert relative file names into absolute ones?
Best
Ari
Best
Ari
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Relative and absolute file names

Post by aaronw »

Are you wanting to canonicalize a path? For example convert "C:\abs\..\abc\file.txt" to "C:\abc\file.txt"? Just curious what is your use need for this?
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: Relative and absolute file names

Post by AriSilva »

Hi Aaron,
I have a need to display the complete (canocalized) name of the directory where the reports will be stored.
This directory is informd in the program as a relative path, such as
dirname = ..\..\.._50_Reports
and this name is concatenated with the filename to store the specific report.
When I show the complete name of the report (including the directory name) I would like to show it as a its proper name, not the relative name.
I know this is not your priority (mine either), it was just to improve the software-user communication.
Best
Ari
Best
Ari
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Relative and absolute file names

Post by Gregory Martin »

You could write a helper function that uses the filename function to get the full name:
function string GetAbsoluteFilename(string relative_filename)
    file temp_file;
    setfile(temp_file, relative_filename);
    GetAbsoluteFilename = filename(temp_file);
    close(temp_file);
end;

// ...

errmsg("%s", GetAbsoluteFilename("..\MyFile.txt"));
That assumes that the file exists.
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: Relative and absolute file names

Post by AriSilva »

Great, Greg.
Thank you, that´s what I needed.
Best
Ari
Best
Ari
Post Reply