1. How check for "path/file exists"?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 03, 2000
- 506 views
Wolf, all, How can I check for whether a specified "path/file" exists?? I'm trying to use Wolf's "jumpto" (or perhaps his "ShellExecute2") to run another program from within my program (to jump to it); when this is a program with a "stable" path, no problem. But I'm wanting to be able to jump to Wolf's tutorial, which isn't always at a known place in the Euphoria folder, so I need to be able to *test* for whether the path/file I tentatively specify actually exists or not, so I can activate the "open file" dialog if it doesn't. I changed Wolf's "jumpto" to a function, thinking to use the return as a test, but while it worked if the path was correct, when the path/file wasn't correct it just bombed & output an error message about "can't open file". Any thoughts? Dan Moyer
2. Re: How check for "path/file exists"?
- Posted by Kat <gertie at PELL.NET> Sep 03, 2000
- 499 views
- Last edited Sep 04, 2000
On 3 Sep 2000, at 19:13, Dan B Moyer wrote: > Wolf, all, > > How can I check for whether a specified "path/file" exists?? > > I'm trying to use Wolf's "jumpto" (or perhaps his "ShellExecute2") to run > another program from within my program (to jump to it); when this is a > program with a "stable" path, no problem. But I'm wanting to be able to > jump to Wolf's tutorial, which isn't always at a known place in the Euphoria > folder, so I need to be able to *test* for whether the path/file I > tentatively specify actually exists or not, so I can activate the "open > file" dialog if it doesn't. > > I changed Wolf's "jumpto" to a function, thinking to use the return as a > test, but while it worked if the path was correct, when the path/file wasn't > correct it just bombed & output an error message about "can't open file". > > Any thoughts? Try opening the file for a read before you try to exec it. If it cannot be opened, then it's not there or it's locked,, either way, you can't run it. Kat
3. Re: How check for "path/file exists"?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 03, 2000
- 495 views
- Last edited Sep 04, 2000
Kat, Ok, I did consider that, but thought there might be a better or more "elegant" way. Thanks. Dan ----- Original Message ----- From: "Kat" <gertie at PELL.NET> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Sunday, September 03, 2000 8:35 PM Subject: Re: How check for "path/file exists"? > On 3 Sep 2000, at 19:13, Dan B Moyer wrote: > > > Wolf, all, > > > > How can I check for whether a specified "path/file" exists?? > > > > I'm trying to use Wolf's "jumpto" (or perhaps his "ShellExecute2") to run > > another program from within my program (to jump to it); when this is a > > program with a "stable" path, no problem. But I'm wanting to be able to > > jump to Wolf's tutorial, which isn't always at a known place in the Euphoria > > folder, so I need to be able to *test* for whether the path/file I > > tentatively specify actually exists or not, so I can activate the "open > > file" dialog if it doesn't. > > > > I changed Wolf's "jumpto" to a function, thinking to use the return as a > > test, but while it worked if the path was correct, when the path/file wasn't > > correct it just bombed & output an error message about "can't open file". > > > > Any thoughts? > > Try opening the file for a read before you try to exec it. If it cannot be opened, then it's > not there or it's locked,, either way, you can't run it. > > Kat
4. Re: How check for "path/file exists"?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 03, 2000
- 474 views
- Last edited Sep 04, 2000
Kat, Tried it, but when no file exists, I get a dos window with message "can't open" filename instead of going on through the if-then. Here's what I wrote: --<code> integer filethere filethere = open("c:\\Euphoria\\Win32Lib\\A new Tutorial\\Tutor3.exw","r") if filethere != -1 then -- is a file there close(filethere) Jump_to( -- passing YOUR main window's id: MainWindow, -- with the program to call: "exw.exe", -- this is MY current 'tutorials' default path !! "c:\\Euphoria\\Win32Lib\\A new Tutorial\\", -- the parameter to pass to exw.exe: "xTutor3.exw", -- for purpose of test, there is no such file -- and last, the 'show' parameter: SW_SHOWDEFAULT ) else end if <code ends> Dan ----- Original Message ----- From: "Kat" <gertie at PELL.NET> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Sunday, September 03, 2000 8:35 PM Subject: Re: How check for "path/file exists"? > On 3 Sep 2000, at 19:13, Dan B Moyer wrote: > > > Wolf, all, > > > > How can I check for whether a specified "path/file" exists?? > > > > I'm trying to use Wolf's "jumpto" (or perhaps his "ShellExecute2") to run > > another program from within my program (to jump to it); when this is a > > program with a "stable" path, no problem. But I'm wanting to be able to > > jump to Wolf's tutorial, which isn't always at a known place in the Euphoria > > folder, so I need to be able to *test* for whether the path/file I > > tentatively specify actually exists or not, so I can activate the "open > > file" dialog if it doesn't. > > > > I changed Wolf's "jumpto" to a function, thinking to use the return as a > > test, but while it worked if the path was correct, when the path/file wasn't > > correct it just bombed & output an error message about "can't open file". > > > > Any thoughts? > > Try opening the file for a read before you try to exec it. If it cannot be opened, then it's > not there or it's locked,, either way, you can't run it. > > Kat
5. Re: How check for "path/file exists"?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 03, 2000
- 471 views
- Last edited Sep 04, 2000
Nevermind, I found it, sigh. Tested for a file that *does* exist, so it then tried to open file that *doesn't*, which failed. argh. Dan ----- Original Message ----- From: "Dan B Moyer" <DANMOYER at prodigy.net> To: "Euphoria Programming for MS-DOS" <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Sunday, September 03, 2000 9:29 PM Subject: Re: How check for "path/file exists"? > Kat, > > Tried it, but when no file exists, I get a dos window with message "can't > open" filename instead of going on through the if-then. > > Here's what I wrote: > > --<code> > integer filethere > > filethere = open("c:\\Euphoria\\Win32Lib\\A new Tutorial\\Tutor3.exw","r") > if filethere != -1 then -- is a file there > close(filethere) > Jump_to( > -- passing YOUR main window's id: > MainWindow, > -- with the program to call: > "exw.exe", > -- this is MY current 'tutorials' default path !! > "c:\\Euphoria\\Win32Lib\\A new Tutorial\\", > -- the parameter to pass to exw.exe: > "xTutor3.exw", -- for purpose of test, there is no such file > -- and last, the 'show' parameter: > SW_SHOWDEFAULT ) > else > > end if > <code ends> > > Dan > > ----- Original Message ----- > From: "Kat" <gertie at PELL.NET> > To: <EUPHORIA at LISTSERV.MUOHIO.EDU> > Sent: Sunday, September 03, 2000 8:35 PM > Subject: Re: How check for "path/file exists"? > > > > On 3 Sep 2000, at 19:13, Dan B Moyer wrote: > > > > > Wolf, all, > > > > > > How can I check for whether a specified "path/file" exists?? > > > > > > I'm trying to use Wolf's "jumpto" (or perhaps his "ShellExecute2") to > run > > > another program from within my program (to jump to it); when this is a > > > program with a "stable" path, no problem. But I'm wanting to be able to > > > jump to Wolf's tutorial, which isn't always at a known place in the > Euphoria > > > folder, so I need to be able to *test* for whether the path/file I > > > tentatively specify actually exists or not, so I can activate the "open > > > file" dialog if it doesn't. > > > > > > I changed Wolf's "jumpto" to a function, thinking to use the return as a > > > test, but while it worked if the path was correct, when the path/file > wasn't > > > correct it just bombed & output an error message about "can't open > file". > > > > > > Any thoughts? > > > > Try opening the file for a read before you try to exec it. If it cannot be > opened, then it's > > not there or it's locked,, either way, you can't run it. > > > > Kat >
6. Re: How check for "path/file exists"?
- Posted by =?iso-8859-1?B?U2tvZGE=?= <tone.skoda at SIOL.NET> Sep 04, 2000
- 501 views
--returns 1 if file exists, 0 if it doesn't global function file_exists(sequence fpath) integer a a=open(fpath,"r") if a=-1 then --not found a=0 else --found close(a) a=1 end if return a end function
7. Re: How check for "path/file exists"?
- Posted by Al Getz <xaxo at AOL.COM> Sep 04, 2000
- 479 views
TESTING FOR A VALID PATH Dan, The problem with opening a file to test for validity is that you can't open a directory name, so here's what i use: -------------------------------------------------------------- -- Path Validation Check -- -- checks for valid directory or filename -------------------------------------------------------------- include file.e include get.e --for this sample only atom retv,ink function ValidatePath(sequence TargetPathName,sequence TargetFileName) object DirEntries DirEntries=dir(TargetPathName&TargetFileName) if atom(DirEntries) then --doesnt exist return 0 else return 1 end if end function --testing for a valid specific filename: ?retv --testing for a valid directory name: ?retv printf(1,"%s\n",{"Press a key..."}) ink=wait_key() ---------------------------------------------------------------- Good luck. --Al
8. Re: How check for "path/file exists"?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 04, 2000
- 499 views
Huh? I did it & it worked as far as I could tell. I did this: fileHandle = open(DefaultPath & DefaultFileName, "r") if fileHandle != -1 then -- tutorial is in default directory: Dan ----- Original Message ----- From: "Al Getz" <xaxo at AOL.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Monday, September 04, 2000 3:46 AM Subject: Re: How check for "path/file exists"? > TESTING FOR A VALID PATH > > Dan, > > The problem with opening a file to test for validity is that you > can't open a directory name, so here's what i use: > > -------------------------------------------------------------- > > -- Path Validation Check -- > > -- checks for valid directory or filename > > -------------------------------------------------------------- > > include file.e > include get.e --for this sample only > > atom retv,ink > > function ValidatePath(sequence TargetPathName,sequence TargetFileName) > > object DirEntries > > DirEntries=dir(TargetPathName&TargetFileName) > if atom(DirEntries) then > --doesnt exist > return 0 > else > return 1 > end if > end function > > --testing for a valid specific filename: > retv=ValidatePath("c:\\euphoria\\projects\\tests\\","test.txt") > ?retv > > --testing for a valid directory name: > retv=ValidatePath("c:\\euphoria\\projects\\emptydir\\","*.*") > ?retv > > > printf(1,"%s\n",{"Press a key..."}) > > ink=wait_key() > > ---------------------------------------------------------------- > > Good luck. > --Al
9. Re: How check for "path/file exists"?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 04, 2000
- 484 views
Skoda, Thanks, that's close to what I did, except I didn't put it into a function, just put it directely in the code since I only used it once. Dan ----- Original Message ----- From: "Skoda" <tone.skoda at SIOL.NET> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Monday, September 04, 2000 2:17 AM Subject: Re: How check for "path/file exists"? > --returns 1 if file exists, 0 if it doesn't > global function file_exists(sequence fpath) > integer a > a=open(fpath,"r") > if a=-1 then > --not found > a=0 > else > --found > close(a) > a=1 > end if > return a > end function
10. Re: How check for "path/file exists"?
- Posted by Al Getz <xaxo at AOL.COM> Sep 04, 2000
- 488 views
Dan, Glad it worked for you. My code was used to test for a valid filename OR directory name. You can't open a directory name with 'open()' so you need another way to test for that. If your only testing for valid filenames i guess it doesnt matter. --Al
11. Re: How check for "path/file exists"?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 04, 2000
- 483 views
Al, Oh, ok, now I understand: you're providing for making a specific check for whether a *directory* exists or not. I didn't really need that, as what I am doing is asserting a "default" pathname for Wolf's Tutorial, and if it isn't there (which I can & do check with open filename), then I open the "open file" dialog to find it & then use it. But that *is* an interesting routine you shared with us! :) Dan ----- Original Message ----- From: "Al Getz" <xaxo at AOL.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Monday, September 04, 2000 3:46 AM Subject: Re: How check for "path/file exists"? > TESTING FOR A VALID PATH > > Dan, > > The problem with opening a file to test for validity is that you > can't open a directory name, so here's what i use: > > -------------------------------------------------------------- > > -- Path Validation Check -- > > -- checks for valid directory or filename > > -------------------------------------------------------------- > > include file.e > include get.e --for this sample only > > atom retv,ink > > function ValidatePath(sequence TargetPathName,sequence TargetFileName) > > object DirEntries > > DirEntries=dir(TargetPathName&TargetFileName) > if atom(DirEntries) then > --doesnt exist > return 0 > else > return 1 > end if > end function > > --testing for a valid specific filename: > retv=ValidatePath("c:\\euphoria\\projects\\tests\\","test.txt") > ?retv > > --testing for a valid directory name: > retv=ValidatePath("c:\\euphoria\\projects\\emptydir\\","*.*") > ?retv > > > printf(1,"%s\n",{"Press a key..."}) > > ink=wait_key() > > ---------------------------------------------------------------- > > Good luck. > --Al
12. Re: How check for "path/file exists"?
- Posted by Michael Nelson <MichaelANelson at WORLDNET.ATT.NET> Sep 04, 2000
- 481 views
A simpler version: function ValidatePath(sequence TargetPathName) return sequence(dir(TargetPathName)) end function No need to separate file and path just so the function can recombine them. -- Mike Nelson ----- Original Message ----- From: "Al Getz" <xaxo at AOL.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Monday, September 04, 2000 3:46 AM Subject: Re: How check for "path/file exists"? > TESTING FOR A VALID PATH > > Dan, > > The problem with opening a file to test for validity is that you > can't open a directory name, so here's what i use: > > -------------------------------------------------------------- > > -- Path Validation Check -- > > -- checks for valid directory or filename > > -------------------------------------------------------------- > > include file.e > include get.e --for this sample only > > atom retv,ink > > function ValidatePath(sequence TargetPathName,sequence TargetFileName) > > object DirEntries > > DirEntries=dir(TargetPathName&TargetFileName) > if atom(DirEntries) then > --doesnt exist > return 0 > else > return 1 > end if > end function > > --testing for a valid specific filename: > retv=ValidatePath("c:\\euphoria\\projects\\tests\\","test.txt") > ?retv > > --testing for a valid directory name: > retv=ValidatePath("c:\\euphoria\\projects\\emptydir\\","*.*") > ?retv > > > printf(1,"%s\n",{"Press a key..."}) > > ink=wait_key() > > ---------------------------------------------------------------- > > Good luck. > --Al
13. Re: How check for "path/file exists"?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 04, 2000
- 518 views
Al, Turns out I did need have them separate, because Wolf's "jump to" has separate parameter fields for path & file . Dan ----- Original Message ----- From: "Michael Nelson" <MichaelANelson at WORLDNET.ATT.NET> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Monday, September 04, 2000 7:32 AM Subject: Re: How check for "path/file exists"? > A simpler version: > > function ValidatePath(sequence TargetPathName) > return sequence(dir(TargetPathName)) > end function > > No need to separate file and path just so the function can recombine them. > > -- Mike Nelson > > ----- Original Message ----- > From: "Al Getz" <xaxo at AOL.COM> > To: <EUPHORIA at LISTSERV.MUOHIO.EDU> > Sent: Monday, September 04, 2000 3:46 AM > Subject: Re: How check for "path/file exists"? > > > > TESTING FOR A VALID PATH > > > > Dan, > > > > The problem with opening a file to test for validity is that you > > can't open a directory name, so here's what i use: > > > > -------------------------------------------------------------- > > > > -- Path Validation Check -- > > > > -- checks for valid directory or filename > > > > -------------------------------------------------------------- > > > > include file.e > > include get.e --for this sample only > > > > atom retv,ink > > > > function ValidatePath(sequence TargetPathName,sequence TargetFileName) > > > > object DirEntries > > > > DirEntries=dir(TargetPathName&TargetFileName) > > if atom(DirEntries) then > > --doesnt exist > > return 0 > > else > > return 1 > > end if > > end function > > > > --testing for a valid specific filename: > > retv=ValidatePath("c:\\euphoria\\projects\\tests\\","test.txt") > > ?retv > > > > --testing for a valid directory name: > > retv=ValidatePath("c:\\euphoria\\projects\\emptydir\\","*.*") > > ?retv > > > > > > printf(1,"%s\n",{"Press a key..."}) > > > > ink=wait_key() > > > > ---------------------------------------------------------------- > > > > Good luck. > > --Al
14. Re: How check for "path/file exists"?
- Posted by gebrandariz <gebrandariz at YAHOO.COM> Sep 19, 2000
- 513 views
Dan: (that's me, always late) ----- Original Message ----- From: Dan B Moyer <DANMOYER at PRODIGY.NET> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Monday, September 04, 2000 1:29 AM Subject: Re: How check for "path/file exists"? > --<code> > integer filethere > > filethere = open("c:\\Euphoria\\Win32Lib\\A new Tutorial\\Tutor3.exw","r") > if filethere != -1 then -- is a file there > close(filethere) > Jump_to( > -- passing YOUR main window's id: > MainWindow, > .....etc. etc..... > <code ends> > > Dan > Try it the other way round: if filethere = -1 then screamforhelp() else processhappily(); or maybe even the Perl way: open(file) or die "Someone swiped my file!"; Gerardo E. Brandariz _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com