Re: Getting full path of a file?
- Posted by Greg Haberek Jul 02, 2008
- 912 views
Jeremy Cowgar said...
Say I do this in Euphoria:
integer fh = open("../../mydir/myfile.txt", "r")
Is there an easy way to get the real full path of that file?
Jeremy
Here's two functions that should help you.
include file.e integer SLASH if platform() = LINUX then SLASH = '/' else SLASH = '\\' end if global function translate_path( sequence path ) -- translates a relative path to an absolute path -- NOTE: the path *must* exist!! sequence temp integer junk -- push the current path temp = current_dir() -- change to the new path if chdir( path ) then -- fetch the new path path = current_dir() -- pop the current path junk = chdir( temp ) else -- invalid path path = "" end if return path end function global function get_file_path( sequence filename ) -- returns just the path part of filename integer found sequence path -- find the last slash for i = length(filename) to 1 by -1 do if filename[i] = SLASH then found = i exit end if end for if found then -- trim path from filename path = filename[1..found-1] else -- no path found, must -- be current directory path = current_dir() end if return path end function
-Greg