1. which directory?
- Posted by John McAdam <johnmcadam at clix.pt> Jan 15, 2002
- 422 views
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
2. Re: which directory?
- Posted by fretinator at smallvue.com Jan 15, 2002
- 430 views
The norm is to use your application directory and append it to you path for the file. So in VB one would use, App.path + "/filename.ext". I'm not real familiar with Euphoria, so I assume you would use the current_dir() function and append the filename. On Tue, 15 Jan 2002, John McAdam wrote: > > 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 > > > >
3. Re: which directory?
- Posted by tone.skoda at siol.net Jan 15, 2002
- 416 views
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 > > > >