1. Getting full path of a file?

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

new topic     » topic index » view message » categorize

2. Re: Getting full path of a file?

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Getting full path of a file?

I don't think you can do that.

It must be:

integer fn

fn=open("../../myfile.txt","r")

new topic     » goto parent     » topic index » view message » categorize

4. Re: Getting full path of a file?

don cole said...

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 smile

sequence name="John", city="Smalltown" 
integer age=12 
 
printf(1, "%s is %d and lives in %s.", {name, age, city}) 

is perfectly valid.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

5. Re: Getting full path of a file?

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

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") 
new topic     » goto parent     » topic index » view message » categorize

6. Re: Getting full path of a file?

Well how come I get this:

unknown command global sequence mystock={"PBR","XOM","REXX"} ^

Don Cole

new topic     » goto parent     » topic index » view message » categorize

7. Re: Getting full path of a file?

don cole said...

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

new topic     » goto parent     » topic index » view message » categorize

8. Re: Getting full path of a file?

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

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

new topic     » goto parent     » topic index » view message » categorize

9. Re: Getting full path of a file?

Jeremy Cowgar said...
don cole said...

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

new topic     » goto parent     » topic index » view message » categorize

10. Re: Getting full path of a file?

don cole said...

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

new topic     » goto parent     » topic index » view message » categorize

11. Re: Getting full path of a file?

thread view on this message is a blank page.
http://openeuphoria.org/EUforum/index.cgi?thread_id=100275#100275

new topic     » goto parent     » topic index » view message » categorize

12. Re: Getting full path of a file?

Jeremy Cowgar said...
don cole said...

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.

new topic     » goto parent     » topic index » view message » categorize

13. Re: Getting full path of a file?

don cole said...

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

new topic     » goto parent     » topic index » view message » categorize

14. Re: Getting full path of a file?

Jeremy Cowgar said...
don cole said...

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.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu