1. Getting full path of a file?
- Posted by Jeremy Cowgar Jul 02, 2008
- 928 views
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
2. Re: Getting full path of a file?
- Posted by Greg Haberek Jul 02, 2008
- 913 views
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
3. Re: Getting full path of a file?
- Posted by don cole Jul 02, 2008
- 925 views
- Last edited Jul 03, 2008
I don't think you can do that.
It must be:
integer fn
fn=open("../../myfile.txt","r")
4. Re: Getting full path of a file?
- Posted by Jeremy Cowgar Jul 02, 2008
- 906 views
- Last edited Jul 03, 2008
I don't think you can do that.
It must be:
integer fn fn=open("../../myfile.txt","r")
4.0 has assign on declaration now
sequence name="John", city="Smalltown" integer age=12 printf(1, "%s is %d and lives in %s.", {name, age, city})
is perfectly valid.
Jeremy
5. Re: Getting full path of a file?
- Posted by Mike777 Jul 03, 2008
- 730 views
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
If using Win32lib it would be:
myPath = getfullPathName ("../../mydir/myfile.txt", w32True) --myPath[1] is the path (whatever is defined by "../../mydir/") --myPath[2] is the file name ("myfile.txt")
6. Re: Getting full path of a file?
- Posted by don cole Jul 03, 2008
- 794 views
Well how come I get this:
unknown command global sequence mystock={"PBR","XOM","REXX"} ^
Don Cole
7. Re: Getting full path of a file?
- Posted by Jeremy Cowgar Jul 03, 2008
- 765 views
Well how come I get this:
unknown command global sequence mystock={"PBR","XOM","REXX"}
What version of Euphoria are you using? That coe works fine over here on 4.0, Rev 795.
Jeremy
8. Re: Getting full path of a file?
- Posted by Jeremy Cowgar Jul 03, 2008
- 760 views
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
From input and examples from here, I came up with:
function fullpath(sequence fname) sequence parts = split(current_dir(), "/\\", 0, 1) & split(dirname(fname), "/\\", 0, 1) sequence new_path = {} for i = 1 to length(parts) do if equal(parts[i], "..") then new_path = new_path[1..$-1] elsif equal(parts[i], ".") then -- do nothing else new_path &= {parts[i]} end if end for return join(new_path, SLASH) end function
Does this like it'll work in all situations? I did not even try it on Windows yet, but seems to work fine on Linux.
Jeremy
9. Re: Getting full path of a file?
- Posted by don cole Jul 04, 2008
- 806 views
Well how come I get this:
unknown command global sequence mystock={"PBR","XOM","REXX"}
What version of Euphoria are you using? That coe works fine over here on 4.0, Rev 795.
I was told ver.4 was only for developers aqnd could not be found on the Euphoria Webpage.
So back to "where do I get ver.4?"
Jeremy
10. Re: Getting full path of a file?
- Posted by Jeremy Cowgar Jul 04, 2008
- 894 views
I was told ver.4 was only for developers aqnd could not be found on the Euphoria Webpage.
So back to "where do I get ver.4?"
Hm, 4.0 is not only for developers. It does take a bit to make it work right now as it is not available in binary format alone. You must be willing to work with SVN. You can download SVN and do:
C:\> svn co http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk euphoria-4.0
Then download the latest .zip file from eubins and place the .exe's and .libs into the C:\euphoria-4.0\bin directory. Then configure your environment properly (PATH and possibly EUINC and EUDIR). You will then be set with 4.0.
Bear in mind, 4.0 has bugs. We have not even hit alpha stage yet. Once it hits alpha, you will then be able to download pre-made versions ready to go, but it will still be buggy. The alpha and beta stages are when massive amounts of bugs will be fixed because users like yourself are using it to find problems.
Jeremy
11. Re: Getting full path of a file?
- Posted by ne1 Jul 04, 2008
- 805 views
thread view on this message is a blank page.
http://openeuphoria.org/EUforum/index.cgi?thread_id=100275#100275
12. Re: Getting full path of a file?
- Posted by don cole Jul 04, 2008
- 879 views
I was told ver.4 was only for developers aqnd could not be found on the Euphoria Webpage.
So back to "where do I get ver.4?"
Hm, 4.0 is not only for developers. It does take a bit to make it work right now as it is not available in binary format alone. You must be willing to work with SVN. You can download SVN and do:
C:\> svn co http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk euphoria-4.0
Then download the latest .zip file from eubins and place the .exe's and .libs into the C:\euphoria-4.0\bin directory. Then configure your environment properly (PATH and possibly EUINC and EUDIR). You will then be set with 4.0.
Bear in mind, 4.0 has bugs. We have not even hit alpha stage yet. Once it hits alpha, you will then be able to download pre-made versions ready to go, but it will still be buggy. The alpha and beta stages are when massive amounts of bugs will be fixed because users like yourself are using it to find problems.
Jeremy
OK I'll work on that. What does SVN?
What I said about
integer counnt = 1
not being legal is not entirely false.
I'm sill trying to fifure out how to use this forum.
Don Cole A Bug is an un-documented feature. A Feature is a documented Bug.
Thanks Jeremy for all you are doing.
13. Re: Getting full path of a file?
- Posted by Jeremy Cowgar Jul 04, 2008
- 806 views
OK I'll work on that. What does SVN?
SVN is a source code management tool that enables many people at remote locations to work on the same source w/o overwriting each persons changes. You can read more about SVN (Subversion) at http://subversion.tigris.org/
Jeremy
14. Re: Getting full path of a file?
- Posted by irv Jul 04, 2008
- 846 views
OK I'll work on that. What does SVN?
SVN is a source code management tool that enables many people at remote locations to work on the same source w/o overwriting each persons changes. You can read more about SVN (Subversion) at http://subversion.tigris.org/
Jeremy
It's really a pretty trivial task to compile, at least on Linux. Don't hesitate to give it a try.