1. RE: Current Directory
- Posted by Al Getz <Xaxo at aol.com> Feb 12, 2003
- 525 views
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 > -- > > 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. Take care, Al
2. RE: Current Directory
- Posted by Christian.CUVIER at agriculture.gouv.fr Feb 12, 2003
- 486 views
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 > ------------------------------ > > Date: Wed, 12 Feb 2003 10:51:07 +0000 > From: Al Getz <Xaxo at aol.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 > > -- > > > > 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. > > Take care, <snip>
3. RE: Current Directory
- Posted by Al Getz <Xaxo at aol.com> Feb 12, 2003
- 490 views
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 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 Take care, Al
4. RE: Current Directory
- Posted by Al Getz <Xaxo at aol.com> Feb 13, 2003
- 491 views
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. 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"? >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. The only way to determine this is to test the checksum because the date and time might be different even though it contains the same file contents. Also, you'll have to avoid writing to files if this is the case, because which file do you write to, and if you choose to write to both, there may yet still be another copy in another directory that hasnt been updated. Good luck with it, Al
5. RE: Current Directory
- Posted by Al Getz <Xaxo at aol.com> Feb 13, 2003
- 506 views
Hello, Having to interface with a file is much easier then having to interface with a human directly, except when it comes to errors. 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 because maintaining a current directory for each drive is not supported in Euphoria, unless Rob plans to do this in 2.4, but i doubt it. As is, the process starts a new current directory and it's only one, not several. If you use the system() command it starts a new process, so you're starting with no current dir names again. 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:\" 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? 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. 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? 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:\" . I think you can check for valid paths by using: object=dir(). So, to repeat the question: How does the user convey the new current directory for a particular drive? Good luck with it, Al 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? 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.
6. RE: Current Directory
- Posted by Brendon Sly <bwsly at infoscience.otago.ac.nz> Feb 13, 2003
- 511 views
> -----Original Message----- > From: Derek Parnell [mailto:ddparnell at bigpond.com] > 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. My function did a simple system call something like: system(sprintf("chdir %s > %s", {drive_letter, temp_filename}), 2) I'd then read the single line in that file and use that instead of, in my case, 'M:' or 'N:'. I used that simple trick to deal with a whole bunch of files in a batch process on Win2000 and I could avoid messing with the current drive/directory, which would have broken the 'main' batch file. > ---------------- > cheers, > Derek Parnell Cheers. Brendon
7. RE: Current Directory
- Posted by rforno at tutopia.com Feb 14, 2003
- 477 views
Derek: I know it's no help, but I had just the same problem when modifying RDS's Duplicate File Finder to correct a bug and enhance it. I was unable to find a solution, as it is said in the corresponding source file (: Regards. ----- Original Message ----- From: Derek Parnell <ddparnell at bigpond.com> Subject: 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 > > > > TOPICA - Start your own email discussion group. FREE! >
8. RE: Current Directory
- Posted by Al Getz <Xaxo at aol.com> Feb 14, 2003
- 505 views
Derek Parnell wrote: > 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 > > Hello again, Pretty neat trick, if you were living back in 1998 In WinXP you get something like 24 dos windows that STAY open. In some versions you might just get flashing windows like you (Derek) had mentioned. This is another reason to avoid using the 'system' command for long term goals. It's an old way of doing things. Also, from a clean boot all i get is the following: C drive: the directory from which the program had started, change the startup dir and this changes. All other drives: No additional directory info except the drive letter like this: D:\, E:\, F:\, etc for all the drives in the system. So a natural question then is HOW do you intend to syncronize your users 'current directories' (of which there could be a possible twenty six!) to YOUR program? Since you said you DONT have to switch directories... Good luck with it, Al