Page 1 of 1

Relative and absolute file names

Posted: April 15th, 2019, 9:41 am
by AriSilva
Is there a function to convert relative file names into absolute ones?
Best
Ari

Re: Relative and absolute file names

Posted: April 16th, 2019, 5:12 pm
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?

Re: Relative and absolute file names

Posted: April 22nd, 2019, 12:10 pm
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

Re: Relative and absolute file names

Posted: April 23rd, 2019, 10:45 am
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.

Re: Relative and absolute file names

Posted: May 1st, 2019, 9:31 am
by AriSilva
Great, Greg.
Thank you, that´s what I needed.
Best
Ari