Re: which directory?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Below is some code which will help you. Directory of application is saved in
command line.

-- returns file directory
-- example: "C:\dir\file.txt" returns "C:\dir"
global function get_file_directory (sequence fname)
 integer c -- current char
 for i = length (fname) to 1 by -1 do
  c = fname [i]
  if c = '\\' or c = '/' then
   return fname [1 .. i - 1]
  elsif c = '.' then
   for j = i - 1 to 1 by -1 do
    c = fname [j]
    if c = '\\' or c = '/' then
     return fname [1 .. j - 1]
    end if
   end for
   return ""
  end if
 end for
 return fname
end function

--/*
-- get_program_directory [Created on 30. September 2001, 15:48]
-- The 'get_program_directory' function returns directory where this program
which is run is.
-- It gets it from parsing command line.
--
-- RETURN VALUES
-- Program directory, string. Like this: "C:\Directory"
--
--*/
global function get_program_directory ()
    --// Command line.
    sequence cmd
    --// Program path + name.
    STRING program_full_path
    --// Returned program directory
    STRING program_directory
    cmd = command_line ()
    if length  (cmd) >=  2 then --// Length of command line is long enough.
        program_full_path = cmd [2]
        program_directory = get_file_directory  (program_full_path)
    else                        --// Length of command line is too short.
        error ("Can't get program directory from command line.")
        program_directory = ""
    end if
    return program_directory
end function

--// This program's directory.
    STRING Program_directory

--/*
-- get_program_file_full_name [Created on 30. September 2001, 15:51]
-- The 'get_program_file_full_name' function joins 'Program_directory' and
'file_name', so that it returns absolute file name.
--
-- PARAMETERS
-- 'file_name'
--    Only file name.
--    This file is assumed to be in directory where program is.
--
-- RETURN VALUES
-- Full absolute file name, with whole path.
--
--*/
function get_program_file_full_name (STRING file_name)
    if equal (Program_directory, {}) = true then --// Program_directory is
{}.
        return file_name
    else                                    --// Program_directory is NOT
{}.
        return Program_directory & "\\" & file_name
    end if
end function


---- Execute this code when program starts: ----

    --// Full file name for crash file.
    STRING crash_full_file_name
    Program_directory = get_program_directory ()
    crash_full_file_name = get_program_file_full_name ("ex.err")
    crash_file (crash_full_file_name)









----- Original Message -----
From: "John McAdam" <johnmcadam at clix.pt>
To: "EUforum" <EUforum at topica.com>
Sent: Tuesday, January 15, 2002 5:55 PM
Subject: which directory?


>
> Hello everybody,
>   So I write a little program and it is in my D:\euphoria\prog\ directory.
I want to
> open a text file which I have also put in the same directory. I open my
program
> by clicking on it and it comes up in the editor, but when I run it, it
can't find my
> text file unless I put in an explicit  "chdir(D:\euphoria\prog\)" first.
That is ok for
> me, but what about somebody who copies my program (and file) to
"e:\wherever\ "
> on their computer? I know I have downloaded programs from the users
contributions
> page and they won't run because of this problem. Kinda frustratin'. If I
ask what
> the current_dir() is, it says "D:euphoria\". Why isn't it my *real*
current directory?
> JOHN
>
>
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu