* Get the path and namefile in run time
@ 2009-10-02 19:54 Pablo
2009-10-02 20:13 ` Dmitry A. Kazakov
2009-10-05 19:43 ` Klaus Jeschke
0 siblings, 2 replies; 6+ messages in thread
From: Pablo @ 2009-10-02 19:54 UTC (permalink / raw)
How can I set a string in run-time with the name of the file and other
with the path?
Say us, If the exec file is in c:\myexecutable\main.exe, I want a way
to set a String in such a way that String1="main.exe" "and c:
\myexecutable\".
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Get the path and namefile in run time
2009-10-02 19:54 Get the path and namefile in run time Pablo
@ 2009-10-02 20:13 ` Dmitry A. Kazakov
2009-10-03 17:09 ` sjw
2009-10-05 13:46 ` Pablo
2009-10-05 19:43 ` Klaus Jeschke
1 sibling, 2 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2009-10-02 20:13 UTC (permalink / raw)
On Fri, 2 Oct 2009 12:54:40 -0700 (PDT), Pablo wrote:
> How can I set a string in run-time with the name of the file and other
> with the path?
> Say us, If the exec file is in c:\myexecutable\main.exe, I want a way
> to set a String in such a way that String1="main.exe" "and c:
> \myexecutable\".
See Ada.Directories, functions:
Simple_Name
Containing_Directory
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Get the path and namefile in run time
2009-10-02 20:13 ` Dmitry A. Kazakov
@ 2009-10-03 17:09 ` sjw
2009-10-05 13:46 ` Pablo
1 sibling, 0 replies; 6+ messages in thread
From: sjw @ 2009-10-03 17:09 UTC (permalink / raw)
On Oct 2, 9:13 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Fri, 2 Oct 2009 12:54:40 -0700 (PDT), Pablo wrote:
> > How can I set a string in run-time with the name of the file and other
> > with the path?
> > Say us, If the exec file is in c:\myexecutable\main.exe, I want a way
> > to set a String in such a way that String1="main.exe" "and c:
> > \myexecutable\".
>
> See Ada.Directories, functions:
>
> Simple_Name
> Containing_Directory
And Ada.Command_Line.Command_Name (actually .. does this include the
".exe" if that wasn't part of what was actually typed at the command
line?)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Get the path and namefile in run time
2009-10-02 20:13 ` Dmitry A. Kazakov
2009-10-03 17:09 ` sjw
@ 2009-10-05 13:46 ` Pablo
2009-10-06 22:06 ` sjw
1 sibling, 1 reply; 6+ messages in thread
From: Pablo @ 2009-10-05 13:46 UTC (permalink / raw)
On 2 out, 17:13, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Fri, 2 Oct 2009 12:54:40 -0700 (PDT), Pablo wrote:
> > How can I set a string in run-time with the name of the file and other
> > with the path?
> > Say us, If the exec file is in c:\myexecutable\main.exe, I want a way
> > to set a String in such a way that String1="main.exe" "and c:
> > \myexecutable\".
>
> See Ada.Directories, functions:
>
> Simple_Name
> Containing_Directory
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de
Hi Dmitry, thanks. The problem of this is that I have to use Ada
95...and Ada.Directories is an Ada 2005 package.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Get the path and namefile in run time
2009-10-02 19:54 Get the path and namefile in run time Pablo
2009-10-02 20:13 ` Dmitry A. Kazakov
@ 2009-10-05 19:43 ` Klaus Jeschke
1 sibling, 0 replies; 6+ messages in thread
From: Klaus Jeschke @ 2009-10-05 19:43 UTC (permalink / raw)
Pablo <pablittto@gmail.com> wrote in news:c199874e-f1af-4a1d-a52d-
88b59e27148d@a7g2000yqo.googlegroups.com:
> How can I set a string in run-time with the name of the file and other
> with the path?
> Say us, If the exec file is in c:\myexecutable\main.exe, I want a way
> to set a String in such a way that String1="main.exe" "and c:
> \myexecutable\".
> Thanks.
>
Hi Pablo,
you did not mention, which OS you use. If you are working on Windows, then
maybe the following may help you. I hope, that the news client does not
reformat the code.
------------------------------------- Program_Name.ads
--
---------------------------------------------------------------------------
--
-- This package provides functions to get the name of the current program
or --
-- parts of it.
--
--
--
-- Maintenance level: 1.01A00
08.10.2008 --
--
---------------------------------------------------------------------------
--
package Program_Name is
function Get_Path_Only return String;
-- This returns the path where the program is located (without prog-name
and extension)
function Get_Full_Path return String;
-- This returns the full name including path and extension
function Get_Full_Path_Length return Integer;
-- This returns the length of the program name including path and
extension
function Get_Name_Length return Integer;
-- This returns the length of the program name without path and without
extension
function Get_Program_Name return String;
-- This returns the name of the program without path and without extension
function Get_Program_Name_First (N : Positive) return String;
-- This returns the first N characters of the program name.
-- If the name is shorter than N characters a 'Constraint_Error' is
raised.
function Get_Program_Name_Last (N : Positive) return String;
-- This returns the last N characters of the program name.
-- If the name is shorter than N characters a 'Constraint_Error' is
raised.
function Get_Program_Name_Before (C : Character) return String;
-- This returns the characters from the beginning up to (but not
including)
-- the first occurrence of the specified character.
-- If there is no character 'C' or 'C' is the first character of the name
-- then an empty string is returned.
function Get_Program_Name_After (C : Character) return String;
-- This returns the characters after the last occurrence of 'C' till the
-- end of the program name
-- If there is no character 'C' then an empty string is returned.
end Program_Name;
------------------------------------- End Program_Name.ads
------------------------------------- Program_Name.adb
--
---------------------------------------------------------------------------
--
-- This package provides functions to get the name of the current program
or --
-- parts of it.
--
--
--
-- Maintenance level: 1.01A00
08.10.2008 --
--
---------------------------------------------------------------------------
--
with Win32;
with Win32.Winbase;
with System;
with Unchecked_Conversion;
package body Program_Name is
function To_PCHAR is new Unchecked_Conversion (System.Address,
Win32.PCHAR);
function Get_Full_Path return String is
Erg : Win32.DWORD;
Path : String (1..1024);
begin
Erg := Win32.Winbase.GetModuleFilename (System.Null_Address, To_PCHAR
(Path'Address), Path'Length);
return Path (1 .. Integer (Erg));
end Get_Full_Path;
function Get_Path_Only return String is
Full_Path : String := Get_Full_Path;
i, j : Integer;
begin
j := Full_Path'Last;
while j > 0
loop
if Full_Path (j) = '\'
then
exit;
end if;
j := j - 1;
end loop;
if j = 0 then return ""; end if;
if Full_Path (j) = '\' then return Full_Path (1 .. j - 1); end if;
return "";
end Get_Path_Only;
function Get_Full_Path_Length return Integer is
Erg : Win32.DWORD;
Path : String (1..1024);
begin
Erg := Win32.Winbase.GetModuleFilename (System.Null_Address, To_PCHAR
(Path'Address), Path'Length);
return Integer (Erg);
end Get_Full_Path_Length;
function Get_Name_Length return Integer is
Name : String := Get_Program_Name;
begin
return Name'Length;
end Get_Name_Length;
function Get_Program_Name return String is
Full_Path : String := Get_Full_Path;
i, j : Integer;
begin
j := Full_Path'Last;
while j > 0
loop
if Full_Path (j) = '.' or Full_Path (j) = '\'
then
exit;
end if;
j := j - 1;
end loop;
if j = 0 then return Full_Path; end if;
if Full_Path (j) = '\' then return Full_Path (j+1 .. Full_Path'Last);
end if;
if Full_Path (j) = '.'
then
j := j - 1;
i := j;
while i > 0
loop
if Full_Path (i) = '\'
then
exit;
end if;
i := i - 1;
end loop;
return Full_Path (i+1 .. j);
else
return "";
end if;
end Get_Program_Name;
function Get_Program_Name_First (N : Positive) return String is
Name : String := Get_Program_Name;
begin
if N > Name'Length
then
raise Constraint_Error;
else
return Name (Name'First .. Name'First + N - 1);
end if;
end Get_Program_Name_First;
function Get_Program_Name_Last (N : Positive) return String is
Name : String := Get_Program_Name;
begin
if N > Name'Length
then
raise Constraint_Error;
else
return Name (Name'Last - N + 1 .. Name'Last);
end if;
end Get_Program_Name_Last;
function Get_Program_Name_Before (C : Character) return String is
Name : String := Get_Program_Name;
i : Integer;
begin
i := Name'First - 1;
while i < Name'Last
loop
i := i + 1;
if Name (i) = C then exit; end if;
end loop;
if Name (i) = C
then
return Name (Name'First .. i - 1);
else
return "";
end if;
end Get_Program_Name_Before;
function Get_Program_Name_After (C : Character) return String is
Name : String := Get_Program_Name;
i : Integer;
begin
i := Name'Last + 1;
while i > Name'First
loop
i := i - 1;
if Name (i) = C then exit; end if;
end loop;
if Name (i) = C
then
return Name (i + 1 .. Name'Last);
else
return "";
end if;
end Get_Program_Name_After;
end Program_Name;
------------------------------------- End Program_Name.adb
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Get the path and namefile in run time
2009-10-05 13:46 ` Pablo
@ 2009-10-06 22:06 ` sjw
0 siblings, 0 replies; 6+ messages in thread
From: sjw @ 2009-10-06 22:06 UTC (permalink / raw)
On Oct 5, 2:46 pm, Pablo <pablit...@gmail.com> wrote:
> Hi Dmitry, thanks. The problem of this is that I have to use Ada
> 95...and Ada.Directories is an Ada 2005 package.
You seem to be on Windows, so perhaps Martin Dowie's pre-05
implementation would help - google 'martin dowie ada.directories'.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-10-06 22:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-02 19:54 Get the path and namefile in run time Pablo
2009-10-02 20:13 ` Dmitry A. Kazakov
2009-10-03 17:09 ` sjw
2009-10-05 13:46 ` Pablo
2009-10-06 22:06 ` sjw
2009-10-05 19:43 ` Klaus Jeschke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox