1. Current Directory

In Windows and DOS environments, how can I get Euphoria to tell me the 
current directory of a drive that is not the current drive?

My understanding is that each drive in a DOS/Windows system has its own 
current directory setting. I know that current_dir() will give me the 
directory that I started running the Euphoria program from, but how do I 
find the current diretory of any of the other drives.

If possible, I'd prefer NOT to use a Windows API or DOS interrupt to get 
the info.

In fact, what I'm trying to do is write a function that is given a filepath 
string, and have it return the same path but in standardized - full - form. 
This should take into consideration any ".\" and "..\" and leading "DRIVE:" 
combinations. I've almost succeeded except for paths given in the form ...

    P:myfolder\myfile.abc

I know the drive "P:" but the rest is supplied relative to the current 
directory *on that drive*! And now I need to know how to get that info.

Maybe somebody has already got a neat function that does all this (hint, 
hint).

I'm not even going to try network paths yet blink
-- 

cheers,
Derek Parnell

new topic     » topic index » view message » categorize

2. Re: Current Directory

well, I tried... in theory, couldn't I save the current directory, switch
drives, read that
directory, then switch back to the directory I saved? well it didnt work... I
though I could
change drives with chdir() but that didnt work... I guess I have to use system()
but I dont like
doing that... any suggestions?


-- begin code snippit --
include file.e

global function any_dir(sequence drive)
sequence old_dir, cur_dir
integer ret

    --store the old directory
    old_dir = current_dir()

    -- change the drive
    ret = chdir(drive)

    -- get that directory
    cur_dir = current_dir()

    -- change back to old directory
    ret = chdir(old_dir)

    return cur_dir

end function

puts(1, any_dir("D:"))
-- end code snippit --

~Greg
g.haberek at comcast.net

----- Original Message -----
From: Derek Parnell <ddparnell at bigpond.com>
To: EUforum <EUforum at topica.com>
Sent: Tuesday, February 11, 2003 11:05 PM
Subject: Current Directory



In Windows and DOS environments, how can I get Euphoria to tell me the
current directory of a drive that is not the current drive?

My understanding is that each drive in a DOS/Windows system has its own
current directory setting. I know that current_dir() will give me the
directory that I started running the Euphoria program from, but how do I
find the current diretory of any of the other drives.

If possible, I'd prefer NOT to use a Windows API or DOS interrupt to get
the info.

In fact, what I'm trying to do is write a function that is given a filepath
string, and have it return the same path but in standardized - full - form.
This should take into consideration any ".\" and "..\" and leading "DRIVE:"
combinations. I've almost succeeded except for paths given in the form ...

    P:myfolder\myfile.abc

I know the drive "P:" but the rest is supplied relative to the current
directory *on that drive*! And now I need to know how to get that info.

Maybe somebody has already got a neat function that does all this (hint,
hint).

I'm not even going to try network paths yet blink
--

cheers,
Derek Parnell



TOPICA - Start your own email discussion group. FREE!

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

3. Re: Current Directory

On Tue, 11 Feb 2003 23:51:56 -0500, Greg Haberek <g.haberek at comcast.net> 
wrote:

>
> well, I tried... in theory, couldn't I save the current directory, switch 
> drives, read that
> directory, then switch back to the directory I saved? well it didnt 
> work... I though I could
> change drives with chdir() but that didnt work... I guess I have to use 
> system() but I dont like
> doing that... any suggestions?
>
>
> -- begin code snippit --
> include file.e
>
> global function any_dir(sequence drive)
> sequence old_dir, cur_dir
> integer ret
>
> --store the old directory
> old_dir = current_dir()
>
> -- change the drive
> ret = chdir(drive)
>
> -- get that directory
> cur_dir = current_dir()
>
> -- change back to old directory
> ret = chdir(old_dir)
>
> return cur_dir
>
> end function
>
> puts(1, any_dir("D:"))
> -- end code snippit --

Yeah, I tried all that too with this code...

 printf(1, "1:%s\n", {current_dir()})
 ? chdir("D:")
 printf(1, "2:%s\n", {current_dir()})

The chdir() returned an error! So did this too...

 printf(1, "1:%s\n", {current_dir()})
 ? chdir("D:\\")
 printf(1, "2:%s\n", {current_dir()})

This time the chdir() said it worked, but the current_dir() was still the 
same!.

-- 

cheers,
Derek Parnell

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

4. Re: Current Directory

chdir() can change the current directory of any given drive, however
it will not change the current drive itself. (4DOS has a command, CDD,
which did this however.) Juergen, we might want to add a chdrive() command
to our file and directory lib.

jbrown

On Wed, Feb 12, 2003 at 04:18:46PM +1100, Derek Parnell wrote:
> 
> On Tue, 11 Feb 2003 23:51:56 -0500, Greg Haberek <g.haberek at comcast.net> 
> wrote:
> 
> >
> >well, I tried... in theory, couldn't I save the current directory, switch 
> >drives, read that
> >directory, then switch back to the directory I saved? well it didnt 
> >work... I though I could
> >change drives with chdir() but that didnt work... I guess I have to use 
> >system() but I dont like
> >doing that... any suggestions?
> >
> >
> >-- begin code snippit --
> >include file.e
> >
> >global function any_dir(sequence drive)
> >sequence old_dir, cur_dir
> >integer ret
> >
> >--store the old directory
> >old_dir = current_dir()
> >
> >-- change the drive
> >ret = chdir(drive)
> >
> >-- get that directory
> >cur_dir = current_dir()
> >
> >-- change back to old directory
> >ret = chdir(old_dir)
> >
> >return cur_dir
> >
> >end function
> >
> >puts(1, any_dir("D:"))
> >-- end code snippit --
> 
> Yeah, I tried all that too with this code...
> 
> printf(1, "1:%s\n", {current_dir()})
> ? chdir("D:")
> printf(1, "2:%s\n", {current_dir()})
> 
> The chdir() returned an error! So did this too...
> 
> printf(1, "1:%s\n", {current_dir()})
> ? chdir("D:\\")
> printf(1, "2:%s\n", {current_dir()})
> 
> This time the chdir() said it worked, but the current_dir() was still the 
> same!.
> 
> -- 
> 
> cheers,
> Derek Parnell
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!

-- 
 /"\  ASCII ribbon              | http://www.geocities.com/jbrown1050/
 \ /  campain against           | Linux User:190064
  X   HTML in e-mail and        | Linux Machine:84163
 /*\  news, and unneeded MIME   |

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

5. Re: Current Directory

Only way that I know of, is to temporary change the current DRIVE,
then check current dir, then change back the drive. (And, you need
to use WinAPI or DOS interrupts to do this, I think.)

There probably is a better way, but I don't know about it sorry.

jbrown

On Wed, Feb 12, 2003 at 03:05:49PM +1100, Derek Parnell wrote:
> 
> In Windows and DOS environments, how can I get Euphoria to tell me the 
> current directory of a drive that is not the current drive?
> 
> My understanding is that each drive in a DOS/Windows system has its own 
> current directory setting. I know that current_dir() will give me the 
> directory that I started running the Euphoria program from, but how do I 
> find the current diretory of any of the other drives.
> 
> If possible, I'd prefer NOT to use a Windows API or DOS interrupt to get 
> the info.
> 
> In fact, what I'm trying to do is write a function that is given a filepath 
> string, and have it return the same path but in standardized - full - form. 
> This should take into consideration any ".\" and "..\" and leading "DRIVE:" 
> combinations. I've almost succeeded except for paths given in the form ...
> 
>    P:myfolder\myfile.abc
> 
> I know the drive "P:" but the rest is supplied relative to the current 
> directory *on that drive*! And now I need to know how to get that info.
> 
> Maybe somebody has already got a neat function that does all this (hint, 
> hint).
> 
> I'm not even going to try network paths yet blink
> -- 
> 
> cheers,
> Derek Parnell
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!

-- 
 /"\  ASCII ribbon              | 
 \ /  campain against           | Linux User:190064
  X   HTML in e-mail and        | Linux Machine:84163
 /*\  news, and unneeded MIME   |

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

6. Re: Current Directory

----- Original Message -----
From: "Al Getz" <Xaxo at aol.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: Current Directory


>
>
> Derek Parnell wrote:
> > In Windows and DOS environments, how can I get Euphoria to tell me the
> > current directory of a drive that is not the current drive?
> >
> > My understanding is that each drive in a DOS/Windows system has its own
> > current directory setting. I know that current_dir() will give me the
> > directory that I started running the Euphoria program from, but how do I
> >
> > find the current diretory of any of the other drives.
> >
> > If possible, I'd prefer NOT to use a Windows API or DOS interrupt to get
> >
> > the info.
> >
> > In fact, what I'm trying to do is write a function that is given a
> > filepath
> > string, and have it return the same path but in standardized - full -
> > form.
> > This should take into consideration any ".\" and "..\" and leading
> > "DRIVE:"
> > combinations. I've almost succeeded except for paths given in the form
> > ...
> >
> >     P:myfolder\myfile.abc
> >
> > I know the drive "P:" but the rest is supplied relative to the current
> > directory *on that drive*! And now I need to know how to get that info.
> >
> > Maybe somebody has already got a neat function that does all this (hint,
> >
> > hint).
> >
> > I'm not even going to try network paths yet blink
> > --
> >
> > cheers,
> > Derek Parnell
> >
> >
> Hello there,
>
> Is there really such a thing in general?
>
> After all, if you open a dos window and at the c:\> prompt type
> D:\
> and then type
> cd "Euphoria"
>
> then type
> C:
> you get the C prompt back, and then type
> D:
> you get the D prompt with the previous 'switched to' directory
> "D:\Euphoria>"
> (as expected)
>
> BUT
>
> if you leave that window open and open another dos window and
> at the C prompt type
> D:
> you get
> "D:\>"
> even though the previous dos window still shows "D:\Euphoria>"
> which means there is no such thing as a 'system wide' current
> directory for each drive and that the current directory is
> particular to the process only.
> This also implies that each process can have it's own current
> directory which has nothing to do with the other processes'.
>
> As is you cant run multiple statements with the 'system' command
> like:
> system("doscommand1,doscommand2, doscommand3",0)
> either, which ideally would run several commands in the
> same dos window.
>
> If you try using a .bat file im pretty sure once the bat file
> stops running all the current directory info is lost anyway,
> so you would have to do all the work within the bat file.
>
> There is nothing to stop you from starting your own 'driver'
> that will keep track of 'current directories' for each drive
> (of course you will have to override a few functions prepending
> the current directory),
> but i think if you look into the original problem you will
> find a better way to do it overall then having to deal with
> multiple current directories.
>
> What is the original problem that prompted you to look for
> the 'current directory' for each drive?
>
> Let us know what you end up doing.

Al,
yes I realize all that you have said is true. But That is NOT what I'm
interested in. I'm NOT trying to change directories or drives. As I said in
my original request...

> > In fact, what I'm trying to do is write a function that is given a
> > filepath
> > string, and have it return the same path but in standardized - full -
> > form.
> > This should take into consideration any ".\" and "..\" and leading
> > "DRIVE:"
> > combinations. I've almost succeeded except for paths given in the form
> > ...
> >
> >     P:myfolder\myfile.abc

I just want to detect if a user supplied file has been already 'seen'
before. I thought that if I converted whatever the user supplied to a
standard form - the FULL path specification - all I have to do then is
compare the two specs to see if they are really the same. For instance...

  C:\autoexec.bat
and
  C:\temp\..\autoexec.bat

refer to the same file even though the USER supplied path's are different.

My problem is in situation where the current drive is say C: and the user
enters "P:bin\xyz.zzy" meaning that the file they want is on the P drive is
is relative to the current directory *for that drive* and not the C: drive.


----------------
cheers,
Derek Parnell

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

7. Re: Current Directory

----- Original Message ----- 
From: <Christian.CUVIER at agriculture.gouv.fr>
To: "EUforum" <EUforum at topica.com>
Subject: RE: Current Directory


> 
> DOS maintains a current directory structure for each drive, so each DOS
> box is likely to maintain its own such array of directory names.
> Look at Ralf Brown's interrupt encyclopedia. There is an int 0x21 call
> that returns this inforation (don't remember it right now, but the value
> in ah lies between 0x39 and 0x47), and also a call to canonicalize path
> names, including UNC, in the way you seem to want (int 0x21 ah=0x60). 
> Sorry, this is direct interrupt calling, but, since the OS provides for
> the feature itself, why perform double work? Sure, it would be nice
> (Open)Eu be able to retrieve this.
> 
> CChris
> 

Yes Chris,
I suspect that I'll have to revert so platform specific coding...

  if platform() = MSDOS then
    -- INT21 call etc..
  elsif platform() = WINDOWS then
    -- Win API call
  else
    -- Unix is easy!
  end if

Pity. I hate doing this sort of thing.

----------------
cheers,
Derek Parnell

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

8. Re: Current Directory

----- Original Message -----
From: "Al Getz" <Xaxo at aol.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: Current Directory


>
> Hello again Derek,
>
>
> Derek wrote:
> >
> >Al,
> >yes I realize all that you have said is true. But That is NOT what I'm
> >interested in. I'm NOT trying to change directories or drives. As I said
> >in
> >my original request...
> >
> Yes, i understand that.  Switching drives was just to show that
> the virtual environment changes with each process, and also that
> is one way to view or 'get' the different 'current' directories.
> By switching drives like that in a dos window you can see the
> different directory names and verify that there really is such
> a notion to begin with smile  The dos window environment doesnt
> forget the current directories for each drive, which is quite
> interesting.
>
> >
> >I just want to detect if a user supplied file has been already 'seen'
> >before. I thought that if I converted whatever the user supplied to a
> >standard form - the FULL path specification - all I have to do then is
> >compare the two specs to see if they are really the same. For
> >instance...
> >
> >C:\autoexec.bat
> >and
> >C:\temp\..\autoexec.bat
> >
> >refer to the same file even though the USER supplied path's are
> >different.
> >
> >My problem is in situation where the current drive is say C: and the
> >user
> >enters "P:bin\xyz.zzy" meaning that the file they want is on the P drive
> >is
> >is relative to the current directory *for that drive* and not the C:
> >drive.
> >
>
> When the system starts up, there is no such knowledge of *any* current
> directories
> like that, so that means your program will have all the knowledge it
> needs
> to ascertain what the user is after.  At some point after your app has
> started
> up, the user had to have conveyed the directory info at some point, so
> you
> could store it in a sequence indexed by drive letter:
>
> sequence dirs,currdir
> dirs={"dirA","dirB","dirC",...}
> currdir=dirs['A'-64]
>
> or something similar to that.  This should cover most platforms
> because you will be handling all the user interactions yourself.
>
>
> You should note however that you are
> asking quite a bit out of your user if you expect them to remember
> current
> directories for a possible 26 drives ('A' to 'Z').  That's one of the
> benefits of using Windows' GetOpenFilename dialog.
>
> If you absolutely cant use GetOpenFilename or whatever then you should
> have some way for your user to select the path from a list rather then
> type it in.  Im sure you can come up with a way to display the necessary
> info?
>
>
> Another possible error could come up:
>
> C:\Euphoria\bin\file1.txt
> C:\Euphoria\Projects\bin\file1.txt
>
> User types in:
> "C:bin\file1.txt"
>
> Which directory are they after?  Will they remember the last current
> directory was C:\Euphoria and not C:\Euphoria\Projects ?
>
>
> Since you are working with the current directories,
> I dont know if you are aware that the current directory is invalid
> for drag and dropped filenames onto the executable file?  The current
> directory always gets set to "C:\" .  This means 'current_dir()' will
> return "C:\" if your user drag and dropped a filename onto your
> executable regardless of where the executable is located or where
> the file was 'dragged' from.  This bites i know, but it's not
> a Euphoria specific problem (sort of).  Windows op sys doesnt return
> the correct directory either, nor does the respective compiled C call.
> Granted, it could be corrected for within the Euphoria internals however
> if Rob really wants to do so.
>
>
> Just some ideas smile
>

Thanks again Al, but absolutely none of what you have said is of any
relevance to the problem I have. I'm obviously finding it difficult to
explain what I need. I'll try again, please be patient.

The user is supplying file names in a text file - not interactively. Thus I
have NO ability to use interactive dialogs to allow the user to select which
files they are referring to. All file names that I get are via a
gets(<filehandle>) call.
However, at the time I read in a file name, I need to be able to find that
file on the system - but only once. So if duplicate file names had been
supplied, I only need to use the first one.

So my problem is this - how can I detect that duplicate file names have been
supplied?

My current way of thinking is that if I convert all file names to their
complete (canonical, full) form, that of <DRIVE>:<PATH><FILENAME> it would
then be a simple matter of comparing strings.

----------------
cheers,
Derek Parnell

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

9. Re: Current Directory

Derek,

Why not just chop apart any drive/dir info from the file names & then
compare just the file names?  You could make a two part sequence, first part
has drive/dir portion, second part has naked filename; then start comparing
just the filenames.  If no dupl filename found, re-combine it into one full
path/filename, then compare next.  If dupl found, stop comparing it,
re-combine its parts, go on to check next.  Each time you re-combine, put it
in another list to actually use.

Dan Moyer

Derek wrote:
> The user is supplying file names in a text file - not interactively. Thus
I
> have NO ability to use interactive dialogs to allow the user to select
which
> files they are referring to. All file names that I get are via a
> gets(<filehandle>) call.
> However, at the time I read in a file name, I need to be able to find that
> file on the system - but only once. So if duplicate file names had been
> supplied, I only need to use the first one.
>
> So my problem is this - how can I detect that duplicate file names have
been
> supplied?
>
> My current way of thinking is that if I convert all file names to their
> complete (canonical, full) form, that of <DRIVE>:<PATH><FILENAME> it would
> then be a simple matter of comparing strings.
>

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

10. Re: Current Directory

Let's do some pseudo-coding! This tends to help me in my engineering classes....

Step 1:  User provides file

-- begin test file --

-- filename: C:\Euphoria\files.txt --
-- please note that the current directory would start at C:\Euphoria --

.\test.dat                       -- file 1 (in C:\Euphoria)
..\test1.dat                    -- file 2 (down one path)
D:\test2.dat                   -- file 3 (different drive)
..\TestFolder\test3.dat   -- file 4 (this is on drive C:, since C:\Euphoria is
the original
directory)
C:\TestFolder\test3.dat  -- file 5 (same as file 4)
D:\FolderName\..\test2.dat -- file 6 (same as file 3)

-- note that the current directory this whole time never changes, --
-- we figure out the pathes based on the base directory --

-- end test file --

Step 2: Filter out duplicate names

-- begin pseudo-code --

function full_path( sequence path )
    -- return a full path name, taking into account any .. or .
end function

sequence list_of_files

while 1 do

    -- read a line from the text file
    -- parse it into a full_path()
    -- look it up in list_of_files

    if  found  then
        -- ignore it, file already listed

    else
        -- add it to the list

    end if

end while

-- end pseudo-code --

Step 3: Begin coding program...


I'm pretty sure this is what Derek wants his program to do!

HTH,
~Greg
g.haberek at comcast.net

----- Original Message -----
From: Dan Moyer <DANIELMOYER at prodigy.net>
To: EUforum <EUforum at topica.com>
Sent: Wednesday, February 12, 2003 9:21 PM
Subject: Re: Current Directory



Derek,

Why not just chop apart any drive/dir info from the file names & then
compare just the file names?  You could make a two part sequence, first part
has drive/dir portion, second part has naked filename; then start comparing
just the filenames.  If no dupl filename found, re-combine it into one full
path/filename, then compare next.  If dupl found, stop comparing it,
re-combine its parts, go on to check next.  Each time you re-combine, put it
in another list to actually use.

Dan Moyer

Derek wrote:
> The user is supplying file names in a text file - not interactively. Thus
I
> have NO ability to use interactive dialogs to allow the user to select
which
> files they are referring to. All file names that I get are via a
> gets(<filehandle>) call.
> However, at the time I read in a file name, I need to be able to find that
> file on the system - but only once. So if duplicate file names had been
> supplied, I only need to use the first one.
>
> So my problem is this - how can I detect that duplicate file names have
been
> supplied?
>
> My current way of thinking is that if I convert all file names to their
> complete (canonical, full) form, that of <DRIVE>:<PATH><FILENAME> it would
> then be a simple matter of comparing strings.
>



TOPICA - Start your own email discussion group. FREE!

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

11. Re: Current Directory

On Wed, 12 Feb 2003 18:21:05 -0800, Dan Moyer <DANIELMOYER at prodigy.net> 
wrote:

>
> Derek,
>
> Why not just chop apart any drive/dir info from the file names & then
> compare just the file names?  You could make a two part sequence, first 
> part
> has drive/dir portion, second part has naked filename; then start 
> comparing
> just the filenames.  If no dupl filename found, re-combine it into one 
> full
> path/filename, then compare next.  If dupl found, stop comparing it,
> re-combine its parts, go on to check next.  Each time you re-combine, put 
> it
> in another list to actually use.
>
> Dan Moyer

Thanks Dan, but that doesn't always work. For example:

  c:\autoexec.bat
and
  c:\temp\autoexec.bat
refer to the different files.

And
  c:\autoexec.bat
and
  c:\temp\..\autoexec.bat

refer to the same file.

But ...
  c:autoexec.bat

refers to a file on C: drive called "autoexec.bat" whose location is in the 
current directory for C: drive. So, how do I find the current directory for 
C: drive? The function current_dir() returns the current directory for the 
drive that was current WHEN you started the program. So if the current 
drive was D: when I started the program, current_dir() might return 
something like "D:\XYZZY\BIN". Which is no use at all if I'm trying to find 
out what the current directory for C: drive is.

Just comparing files names is obviously not going to work. Just comparing 
the user-supplied path specification is not going to work 'cos of the ".\" 
and "..\" constructs that could be present. The main difficulty is when a 
RELATIVE path is specified for a drive that is NOT the current drive - all 
the other situations I can handle.


-- 

cheers,
Derek Parnell

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

12. Re: Current Directory

On Wed, 12 Feb 2003 21:59:44 -0500, Greg Haberek <g.haberek at comcast.net> 
wrote:

>
> Let's do some pseudo-coding! This tends to help me in my engineering 
> classes....
>
> Step 1:  User provides file
>
> -- begin test file --
>
> -- filename: C:\Euphoria\files.txt --
> -- please note that the current directory would start at C:\Euphoria --
>
> .\test.dat                       -- file 1 (in C:\Euphoria)
> ..\test1.dat                    -- file 2 (down one path)
> D:\test2.dat                   -- file 3 (different drive)
> ..\TestFolder\test3.dat   -- file 4 (this is on drive C:, since 
> C:\Euphoria is the original
> directory)
> C:\TestFolder\test3.dat  -- file 5 (same as file 4)
> D:\FolderName\..\test2.dat -- file 6 (same as file 3)
>
> -- note that the current directory this whole time never changes, --
> -- we figure out the pathes based on the base directory --
>
> -- end test file --
>
> Step 2: Filter out duplicate names
>
> -- begin pseudo-code --
>
> function full_path( sequence path )
> -- return a full path name, taking into account any .. or .
> end function
>
> sequence list_of_files
>
> while 1 do
>
> -- read a line from the text file
> -- parse it into a full_path()
> -- look it up in list_of_files
>
> if  found  then
> -- ignore it, file already listed
>
> else
> -- add it to the list
>
> end if
>
> end while
>
> -- end pseudo-code --
>
> Step 3: Begin coding program...
>
>
> I'm pretty sure this is what Derek wants his program to do!

Almost, but not quite. How would the algorithm above handle these two 
specs...

  D:FolderName\..\test2.dat

Notice that there is NO "\" between the ":" and the "FolderName". This is 
the situation that I don't know how to handle.

Then if D:\XYZZY\test2.dat is supplied, how can I know if that is the same 
file as D:\FolderName\..\test2.dat ? It is possibly the same file, but 
maybe not also.

-- 

cheers,
Derek Parnell

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

13. Re: Current Directory

----- Original Message -----
From: "Al Getz" <Xaxo at aol.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: Current Directory


>
> Derek,
>
> Because your questions seem very detailed the best thing you can
> do is supply us with a list of file entries (line by line) and
> a comment as to what is supposed to happen with that particular
> entry.  I would say you should supply at least 20 fully commented
> examples.

There are NOT that many possibilities, Al. Here are all the possible
combinations...

a)  <filename>
b)  <relativepath>\<filename>
c)  <absolutepath>\<filename>
d)  <curdrive>:<filename>
e)  <curdrive>:<relativepath>\<filename>
f)  <curdrive>:<absolutepath>\<filename>
g)  <otherdrive>:<filename>
h)  <otherdrive>:<relativepath>\<filename>
i)  <otherdrive>:<absolutepath>\<filename>

Where <filename> includes an optional extention such as ".bat"
   <relativepath> has the form <foldername>[\<foldername>]...
   <absolutepath> has the form \<relativepath>
   <foldername> also include "." and ".." special folders.
   <curdrive> is the drive letter of the Current drive.
   <otherdrive> is a drive letter of a drive that is NOT the current drive.

Here is how I expect them to be resolved...
a)  <curdrive>:<curdir>\<filename>
b)  <curdrive>:<curdir>\<relativepath>\<filename>
c)  <curdrive>:<absolutepath>\<filename>
d)  <curdrive>:<curdir>\<filename>
e)  <curdrive>:<curdir>\<relativepath>\<filename>
f)  <curdrive>:<absolutepath>\<filename>
g)  <otherdrive>:<???>\<filename>
h)  <otherdrive>:<???>\<relativepath>\<filename>
i)  <otherdrive>:<absolutepath>\<filename>

Where <curdir> is the current directory minus the current drive specifier
but includes the leading slash.
      <???> is what I don't know how to find out using standand Euphoria. It
is the current directory for <otherdrive>.

> It would be a good idea to use the format shown in another
> reply:
>
> [line1] D:\ThisDir\ThatDir\file1.txt --file #1, location only
> [line2] D:                           --command
> [line3] D:\ThatDir\file1.txt         --file #2, location only
> [line4] D:ThatDir\file1.txt          --file #2 again
> [line5] blah blah                    --command
>
>
> Some additional comments...
>
> >D:FolderName\..\test2.dat
>
> >Notice that there is NO "\" between the ":" and the "FolderName". This
> >is
> >the situation that I don't know how to handle.
>
> This doesnt sound that hard.  You have to answer the question:
> Does this format differ from the standard format for a reason,
> or should it be converted into: "D:\FolderName\..\test2.dat"?

Yes it does differ for a reason! 'Cos that's how the user entered it. It is
not meant to be transformed by inserting the slash because that would be the
WRONG thing to do.

>
> >Then if D:\XYZZY\test2.dat is supplied, how can I know if that is the
> >same
> >file as D:\FolderName\..\test2.dat ? It is possibly the same file, but
> >maybe not also.
>
> The file cant be exactly the same file, but might be a replica.

You are right. I gave the wrong example. I meant to have said
"D:FolderName\..\test2.dat" and they can be the same file - and I don't mean
a replica or copy. I mean literally the same file. This is basic Microsoft
file syntax.

   D:\XYZZY\test2.dat  ==> The file called "test.dat" can be found on the
'D' drive in the folder called 'XYZZY'.

   D:FolderName\..\test2.dat ==> The file called "test.dat" can be found on
the 'D' drive. First go to the current folder for that drive, then to the
'FolderName' folder, then go to its parent folder. The file can be found
there. Now if it so happened that the current directory for the D drive was
XYZZY then these two file references refer to exactly the same file.

Try this .BAT file in a DOS window.

@echo off
c:
cd \
mkdir test1
echo >test1\file.dat TEST A
d:
cd \
mkdir test2
echo >test2\file.dat TEST B
cd test2
c:
type c:test1\file.dat
type d:file.dat

--------
Note that the current directory for C: is "\" and the current directory for
D: is "\test2". But all I had to do to access the D: file was enter
"D:file.dat".

So how can I find out, using basic Euphoria, what is the current directory
for ANY drive in the system?

I know I can use DOS INT21 command and WinAPI call, but I'd rather avoid
that if possible.

----------------
cheers,
Derek Parnell

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

14. Re: Current Directory

----- Original Message -----
From: "Al Getz" <Xaxo at aol.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: Current Directory


>
> Hello,
>
> Having to interface with a file is much easier then having
> to interface with a human directly, except when it comes to
> errors.

Agreed. However that is the scenario I have to work with here.

> Derek wrote:
> >So how can I find out, using basic Euphoria, what is the current
> >directory
> >for ANY drive in the system?
>
> I dont think you can do that

I'm pretty sure I can't either. It looks like I will have to resort to some
low-level coding to do it.

> because maintaining a
> current directory for each drive is not supported in Euphoria,

What? "maintaining"? I thought the operating system was doing that?

> unless Rob plans to do this in 2.4, but i doubt it.

Or ever, for that matter.

> As is, the process starts a new current directory and
> it's only one, not several.

This is NOT true. There is a current directory for each drive in the system.
There is only one current drive though at any given time.

>If you use the system()
> command it starts a new process, so you're starting with
> no current dir names again.

Not true. The current directories are inherited from the process that runs
the system() call.

> One attempt is to use the system() command using the dos
> "cd mydir" command.  This would probably work, except as
> soon as the command returns the directory is long forgotten
> so when you go to access the drive with the next system()
> command the current directory is back to "C:\"   smile

This is true. But I'm NOT trying to change directories, just trying to find
out what they are.

> I guess you could create a dos server app but is it really
> worth it, and will it be as platform independent as you're
> looking for?

Yes. This would not be a good approach.

> On the other hand, maintaining a list yourself really isnt that
> hard.  Use a sequence acessed by the drive letter and that
> will return (or set) the current directory for each drive.
> Not much of a problem.  You can then use this info to resolve
> all your paths that are of the relative type.  How hard can
> that really be?  No direct dependence on dos either.

Al, this is the VERY problem I've got. True, once a list like this is
created, it would be easy to use it. But how does one create such a list in
the first place? Have you got any code which can do this?

> You'll have to parse each path into it's type first, then
> update the drive list as required.
>
> The only thing you havent told us is how the user's data tells
> you when they decide to switch current directories for a
> particular drive?

Who said anything about changing directories? I'm just trying to find out
what each drive's current directory is. I don't want to change anything.

> Note that the form:
>
>   d:directory\filename.txt
>
> cant be the first entry in the file because it contains a
> relative path, and since there hasnt yet been a current
> directory established for that drive (other then "d:\"),
> this path would be invalid or it would have to name a path
> using the current directory "d:\" .

This is not true. When my application starts running, the operating system
has already established the current directory for each drive. The Euphoria
function 'current-dir()' just returns the current directory of THE CURRENT
DRIVE, not the current directories of any of the other drives.

> I think you can check for valid paths by using:
> object=dir().

Of course I can. In fact that's what I do. But the dir() function doesn't
help in the two cases I've already mentioned.

   object = dir("D:folder\\test.dat")

just returns the some file info if the file exists. WHat it doesn't return
is the file's exact location.

> So, to repeat the question:
> How does the user convey the new current directory for
> a particular drive?

They don't. They are not trying to either!

The scenario is this...
(a)  A user creates a text file that may contain references to files.
(b)  Some time after this, my application reads this file and when it
detects a file reference, it trys to see if the file referenced, has already
been referenced some where else in the text file. If it hasn't, my
application then reads the referenced file. If it has been previously read,
I avoid reading it again.

That's it! That's all I want to do. Not changing directories.

> Good luck with it,

Thanks. I hate doing DOS INT21 coding blink

> PS
> In most of my apps i've almost eliminated the concept of
> 'current directory' altogether because how do you know what
> it really is: startup directory or working directory?

BINGO! But I have no choice in this case. I have to find out.

> This means im now labeling my special directories
> "StartupDirectory" and "WorkingDirectory" respectively
> which clears matters up completely.
> I never have to maintain a current directory for each drive
> because i always use the full path, except for those two above,
> in which case i'll still use the full path but i'll construct
> it from one of those two.

However, I have users that are typing up the file references - I have no
control over what they do.

----------------
cheers,
Derek Parnell

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

15. Re: Current Directory

On Fri, 14 Feb 2003 10:07:39 +1300, Brendon Sly 
<bwsly at infoscience.otago.ac.nz> wrote:

>
>> -----Original Message-----
>> From: Derek Parnell [mailto:ddparnell at bigpond.com]
>> Sent: Thursday, 13 February 2003 10:45 p.m.
>> To: EUforum
>> Subject: Re: Current Directory
>>
>
> Hi Derek,
>
> <enormous snip>
>>
>> So how can I find out, using basic Euphoria, what is the current 
>> directory
>> for ANY drive in the system?
>>
>> I know I can use DOS INT21 command and WinAPI call, but I'd rather avoid
>> that if possible.
>
> I've no idea how you'd do a generic solution that'd work on anything, 
> but..
>
> I had to do something like this a while back but since my app was being
> called from a batch file, I could 'cheat' and make use of the 'chdir'
> command. If you type 'chdir X:' (where X is the drive you're interested 
> in)
> at a DOS prompt, it'll return the current directory for that drive,
> according to that DOS session.
>

Thank you Brendon. I didn't know the CHDIR trick. Here is the code that I 
tried it out with.
----------
object x
integer fh
sequence dirs
-- Create a file to collect data in.
fh = open("d.d", "w")
close(fh)                           -- Collect the current directory for 
each drive.
for i = 'c' to 'z' do
    system("chdir " & i & ": >>d.d",0)
end for

-- Now read the directories into a sequence.
dirs = {}
fh = open("d.d", "r")
x = gets(fh)
while sequence(x) do
    -- strip of the LF
    x = x[1..length(x)-1]
    dirs = append(dirs, x)
    x = gets(fh)
end while
close(fh)

-- Proof: Display the directories from the sequence.
for i = 1 to length(dirs) do
    printf(1, "%d ==> %s\n", {i,dirs[i]})
end for

--------------
This works. However when running it under EXW.EXE it looks terrible. All 
those flashing windows! I'll live with it for now though. Thanks again for 
this tip.

-- 

cheers,
Derek Parnell

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

16. Re: Current Directory

Derek,
I think this is what you want:

integer fn
fn=3Dopen("test.bat","w")
puts(fn,"cd c:>C:\\temp\\d.txt\ncd D:>>C:\\temp\\d.txt\n")
close(fn)
system("test.bat",2)

Now have a look in d.txt.

Pete

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

17. Re: Current Directory

On Fri, 14 Feb 2003 10:07:39 +1300, Brendon Sly
<bwsly at infoscience.otago.ac.nz> wrote:

Exactly the same trick I just dreamt up, probably without even having
to think too hard or go experimenting ;-(

Pete

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

18. Re: Current Directory

On Fri, 14 Feb 2003 01:45:37 +0000, Pete Lomax <petelomax at blueyonder.co.uk> 
wrote:

>
> Derek,
> I think this is what you want:
>
> integer fn
> fn=open("test.bat","w")
> puts(fn,"cd c:>C:\\temp\\d.txt\ncd D:>>C:\\temp\\d.txt\n")
> close(fn)
> system("test.bat",2)
>
> Now have a look in d.txt.
>
Thanks Pete. --

cheers,
Derek Parnell

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

19. Re: Current Directory

Hello Jim,

I'm very sorry for the late reply! This huge thread happened, when I was
some time away from my PC, and just now I read your post.

You wrote:

> chdir() can change the current directory of any given drive, however
> it will not change the current drive itself.

This is true for Eu DOS32's "chdir()". Apparently it functions the same
as DOS's "cd". Mike Nelson explained it to me here in EUforum on 2 Jun
2002. He also wrote:
"Either Windows or Eu WIN32 chnages the drive automatically.
 For DOS, just add system("c:", 2) before the 'chdir' and it will give
 you the results you are seeking"

> (4DOS has a command, CDD, which did this however.) Juergen, we might
> want to add a chdrive() command to our file and directory lib.

Personally, I don't like so much chdrive()ing and chdir()ing separately.
I already have the following function on my hard disk:

----------=----------=----------=----------=----------=
include file.e

global function cdd (sequence path)
   -- change drive and directory
   -- after a post by Mike Nelson on the Euphoria mailing list
   if platform() = DOS32 and find(':', path) = 2 then
      system(path[1..2], 2)
   end if
   return chdir(path)
end function
----------=----------=----------=----------=----------=

What do you think about it?

Best regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |  while not asleep do
 \ /  against HTML in       |     sheep += 1
  X   e-mail and news,      |  end while
 / \  and unneeded MIME     |

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

Search



Quick Links

User menu

Not signed in.

Misc Menu