I want to determine if a table exists. If the table does exist, I
want to USE it. Otherwise, I don't want to do anything.

I thought there was something like...

IF EXISTS(mytable)
USE mytable in 0
ELSE
* Do nothing.
ENDIF

...But I cannot find a function like "EXISTS()."

Thanks very much for any help.

David

Re: Determing if a table exists; if so, then open by Gene

Gene
Tue Jun 19 11:15:32 CDT 2007

David <David.Aman@dpsnc.net> wrote:

>I want to determine if a table exists. If the table does exist, I
>want to USE it. Otherwise, I don't want to do anything.
>
>I thought there was something like...
>
>IF EXISTS(mytable)
> USE mytable in 0
>ELSE
> * Do nothing.
>ENDIF
>
>...But I cannot find a function like "EXISTS()."

file() might be it for you. Caveat: If you do not specify a
directory, VFP will search the path as well as the current directory.

>Thanks very much for any help.

You are welcome.

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Re: Determing if a table exists; if so, then open by Stefan

Stefan
Tue Jun 19 11:14:31 CDT 2007


"David" <David.Aman@dpsnc.net> schrieb im Newsbeitrag
news:1182267355.345077.73400@c77g2000hse.googlegroups.com...
>I want to determine if a table exists. If the table does exist, I
> want to USE it. Otherwise, I don't want to do anything.
>
> I thought there was something like...
>
> IF EXISTS(mytable)
> USE mytable in 0
> ELSE
> * Do nothing.
> ENDIF
>
> ...But I cannot find a function like "EXISTS()."

You can use the native FILE() function on 'your.DBF'. Or try Try/Catch:

Local llSuccess, lcError, loException As Exception
llSuccess = .T.
Try
Use mytable
Catch To loException
llSuccess = .F.
lcError = m.loException.Message
EndTry


hth
-Stefan


--
|\_/| ------ ProLib - programmers liberty -----------------
(.. ) Our MVPs and MCPs make the Fox run....
- / See us at www.prolib.de or www.AFPages.de
-----------------------------------------------------------



Re: Determing if a table exists; if so, then open by Anders

Anders
Tue Jun 19 11:43:51 CDT 2007

ADIR() will create an array of one row with 5 pieces of info if it finds a
specific file. If you just specify a folder\*.* all the files in the folder
will be returned
-Anders

"David" <David.Aman@dpsnc.net> wrote in message
news:1182267355.345077.73400@c77g2000hse.googlegroups.com...
>I want to determine if a table exists. If the table does exist, I
> want to USE it. Otherwise, I don't want to do anything.
>
> I thought there was something like...
>
> IF EXISTS(mytable)
> USE mytable in 0
> ELSE
> * Do nothing.
> ENDIF
>
> ...But I cannot find a function like "EXISTS()."
>
> Thanks very much for any help.
>
> David
>



Re: Determing if a table exists; if so, then open by Paul

Paul
Tue Jun 19 18:57:39 CDT 2007

"Stefan Wuebbe" <stefan.wuebbe@gmx.de> wrote in message
news:uGVI4zosHHA.1672@TK2MSFTNGP06.phx.gbl...
>
> "David" <David.Aman@dpsnc.net> schrieb im Newsbeitrag
> news:1182267355.345077.73400@c77g2000hse.googlegroups.com...
>>I want to determine if a table exists. If the table does exist, I
>> want to USE it. Otherwise, I don't want to do anything.
>>
>> I thought there was something like...
>>
>> IF EXISTS(mytable)
>> USE mytable in 0
>> ELSE
>> * Do nothing.
>> ENDIF
>>
>> ...But I cannot find a function like "EXISTS()."
>
> You can use the native FILE() function on 'your.DBF'. Or try Try/Catch:
>
> Local llSuccess, lcError, loException As Exception
> llSuccess = .T.
> Try
> Use mytable
> Catch To loException
> llSuccess = .F.
> lcError = m.loException.Message
> EndTry
>
>
> hth
> -Stefan

There's also INDBC(), if you're using a database. That way you don't have to
keep track of the path.




RE: Determing if a table exists; if so, then open by Mark

Mark
Wed Jun 20 04:41:02 CDT 2007

Hi David,
Have a look at FOPEN().
hth
Mark

"David" wrote:

> I want to determine if a table exists. If the table does exist, I
> want to USE it. Otherwise, I don't want to do anything.
>
> I thought there was something like...
>
> IF EXISTS(mytable)
> USE mytable in 0
> ELSE
> * Do nothing.
> ENDIF
>
> ....But I cannot find a function like "EXISTS()."
>
> Thanks very much for any help.
>
> David
>
>

Re: Determing if a table exists; if so, then open by RGBean

RGBean
Wed Jun 20 23:21:30 CDT 2007

Gene,
Even if you specify a full directory qualification, if FILE() doesn't find
it there, it will search the standard VFP paths. (I NEVER use FILE() because
of this!)

Rick

"Gene Wirchenko" <genew@ocis.net> wrote in message
news:c40g73hubscbe6kv6gr88tt36oh9qidjks@4ax.com...
> David <David.Aman@dpsnc.net> wrote:
>
>>I want to determine if a table exists. If the table does exist, I
>>want to USE it. Otherwise, I don't want to do anything.
>>
>>I thought there was something like...
>>
>>IF EXISTS(mytable)
>> USE mytable in 0
>>ELSE
>> * Do nothing.
>>ENDIF
>>
>>...But I cannot find a function like "EXISTS()."
>
> file() might be it for you. Caveat: If you do not specify a
> directory, VFP will search the path as well as the current directory.
>
>>Thanks very much for any help.
>
> You are welcome.
>
> Sincerely,
>
> Gene Wirchenko
>
> Computerese Irregular Verb Conjugation:
> I have preferences.
> You have biases.
> He/She has prejudices.


Re: Determing if a table exists; if so, then open by Steve

Steve
Thu Jun 21 08:28:35 CDT 2007

Rick,
The VFP9 doc says VFP searches the VFP path if no path is specified,
but is not specific for the situation where the path is specified. I
had assumed it always searched ONLY the path specified, so thanks for
pointing out that "mis"behavior.

My brief testing on an XP machine found it will search the unwanted
path(s) only if the path specified is the root directory or ".\" or
not specified.

But this behavior is enough to make me very leery of using FILE() in
the future.

Steve M.



On Thu, 21 Jun 2007 00:21:30 -0400, "RGBean"
<rgbean@NOSPAMmelange-inc.com> wrote:

>Gene,
>Even if you specify a full directory qualification, if FILE() doesn't find
>it there, it will search the standard VFP paths. (I NEVER use FILE() because
>of this!)
>
>Rick
>.............


Re: Determing if a table exists; if so, then open by Cy

Cy
Thu Jun 21 15:27:33 CDT 2007

RGBean wrote:
> Gene,
> Even if you specify a full directory qualification, if FILE() doesn't
> find it there, it will search the standard VFP paths. (I NEVER use
> FILE() because of this!)
>
> Rick
>
> "Gene Wirchenko" <genew@ocis.net> wrote in message
> news:c40g73hubscbe6kv6gr88tt36oh9qidjks@4ax.com...
>> David <David.Aman@dpsnc.net> wrote:
>>
>>> I want to determine if a table exists. If the table does exist, I
>>> want to USE it. Otherwise, I don't want to do anything.
>>>
>>> I thought there was something like...
>>>
>>> IF EXISTS(mytable)
>>> USE mytable in 0
>>> ELSE
>>> * Do nothing.
>>> ENDIF
>>>
>>> ...But I cannot find a function like "EXISTS()."
>>
>> file() might be it for you. Caveat: If you do not specify a
>> directory, VFP will search the path as well as the current directory.
>>
>>> Thanks very much for any help.
>>
>> You are welcome.
>>
>> Sincerely,
>>
>> Gene Wirchenko
>>
>> Computerese Irregular Verb Conjugation:
>> I have preferences.
>> You have biases.
>> He/She has prejudices.
>
Thats easily dealt with. Just store your path with SET("PATH") and then
SET PATH TO, do your file operation and then reset the path. Of course
most of the time I WANT file() to do just what it does. I don't know in
my code where the file is likely to be, but I know it's going to be on
the path.

--
Cy Welch
Senior Programmer
MetSYS Inc
http://www.metsysinc.com

Re: Determing if a table exists; if so, then open by Paul

Paul
Thu Jun 21 15:52:06 CDT 2007

I do not believe that is the case. According to the documentation, FoxPro
searches its path only when a path is not specifically included in the
parameter passed to FILE().

Furthermore, that matches the results of my own testing. For instance,
FILE("myfolder1\myfolder2\myfile.txt") returns .F. even if the file
myfolder1\myfile.txt exists and is in the current path setting.

LOCFILE() does what you described, but it also will pop up a window
prompting the user to locate the file if it cannot be found.



"RGBean" <rgbean@NOSPAMmelange-inc.com> wrote in message
news:173F5120-D4E9-41F8-80F9-3E35DDFAE225@microsoft.com...
> Gene,
> Even if you specify a full directory qualification, if FILE() doesn't
> find it there, it will search the standard VFP paths. (I NEVER use FILE()
> because of this!)
>
> Rick
>
> "Gene Wirchenko" <genew@ocis.net> wrote in message
> news:c40g73hubscbe6kv6gr88tt36oh9qidjks@4ax.com...
>> David <David.Aman@dpsnc.net> wrote:
>>
>>>I want to determine if a table exists. If the table does exist, I
>>>want to USE it. Otherwise, I don't want to do anything.
>>>
>>>I thought there was something like...
>>>
>>>IF EXISTS(mytable)
>>> USE mytable in 0
>>>ELSE
>>> * Do nothing.
>>>ENDIF
>>>
>>>...But I cannot find a function like "EXISTS()."
>>
>> file() might be it for you. Caveat: If you do not specify a
>> directory, VFP will search the path as well as the current directory.
>>
>>>Thanks very much for any help.
>>
>> You are welcome.
>>
>> Sincerely,
>>
>> Gene Wirchenko
>>
>> Computerese Irregular Verb Conjugation:
>> I have preferences.
>> You have biases.
>> He/She has prejudices.
>



Re: Determing if a table exists; if so, then open by Rush

Rush
Fri Jun 22 13:10:48 CDT 2007

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Take a look at the FILER.DLL which is unsupported by MS, but seems to
work correctly.&nbsp; <br>
<br>
Assume we're in a VFP 8 default directory.&nbsp; Labels.dbf exists, but
C:\Labels.dbf doesn't.<br>
<blockquote><tt>oMyFiler = CREATEOBJECT('Filer.FileUtil')<br>
oMyFiler.SearchPath = '.\'<br>
oMyFiler.FileExpression = 'Labels.dbf'<br>
<br>
? FILE('Labels.dbf')&nbsp; &amp;&amp; returns .T.<br>
? oMyFiler.Find(0)&nbsp; &amp;&amp; returns 1 (files found)<br>
<br>
oMyFiler.FileExpression = 'C:\Labels.dbf'<br>
<br>
? FILE('MyFile.dbf')&nbsp; &amp;&amp; returns .T.&nbsp; [BZZZZT!]<br>
? oMyFiler.Find(0)&nbsp; &amp;&amp; returns (no files found in c:\)</tt>
<br>
<br>
</blockquote>
&nbsp;- Rush<br>
<br>
<br>
<br>
<br>
&nbsp;- Rush<br>
<br>
<br>
<br>
David wrote:
<blockquote
cite="mid:1182267355.345077.73400@c77g2000hse.googlegroups.com"
type="cite">
<pre wrap="">I want to determine if a table exists. If the table does exist, I
want to USE it. Otherwise, I don't want to do anything.

I thought there was something like...

IF EXISTS(mytable)
USE mytable in 0
ELSE
* Do nothing.
ENDIF

...But I cannot find a function like "EXISTS()."

Thanks very much for any help.

David

</pre>
</blockquote>
</body>
</html>

Re: Determing if a table exists; if so, then open by Cy

Cy
Mon Jun 25 22:54:38 CDT 2007

Paul Pedersen wrote:
> I do not believe that is the case. According to the documentation, FoxPro
> searches its path only when a path is not specifically included in the
> parameter passed to FILE().
>
> Furthermore, that matches the results of my own testing. For instance,
> FILE("myfolder1\myfolder2\myfile.txt") returns .F. even if the file
> myfolder1\myfile.txt exists and is in the current path setting.
>
> LOCFILE() does what you described, but it also will pop up a window
> prompting the user to locate the file if it cannot be found.

Test by looking for a file in the root directory of ANY drive, and it
will look on the path because for some reason the programmers didn't
consider a drive letter without additional path (such as "c:" or "c:\")
to be a path. IIRC this is not new behavior but have been this way
since at least FPD 2.0.

--
Cy Welch
Senior Programmer
MetSYS Inc
http://www.metsysinc.com

Re: Determing if a table exists; if so, then open by Paul

Paul
Tue Jun 26 11:36:55 CDT 2007


"Cy Welch" <cywelch@yahoo.com> wrote in message
news:umLd6W6tHHA.3588@TK2MSFTNGP06.phx.gbl...
> Paul Pedersen wrote:
>> I do not believe that is the case. According to the documentation, FoxPro
>> searches its path only when a path is not specifically included in the
>> parameter passed to FILE().
>>
>> Furthermore, that matches the results of my own testing. For instance,
>> FILE("myfolder1\myfolder2\myfile.txt") returns .F. even if the file
>> myfolder1\myfile.txt exists and is in the current path setting.
>>
>> LOCFILE() does what you described, but it also will pop up a window
>> prompting the user to locate the file if it cannot be found.
>
> Test by looking for a file in the root directory of ANY drive, and it will
> look on the path because for some reason the programmers didn't consider a
> drive letter without additional path (such as "c:" or "c:\") to be a path.
> IIRC this is not new behavior but have been this way since at least FPD
> 2.0.


Well, I didn't try that. But frankly, to keep files in a root directory
seems like a bad practice.




Re: Determing if a table exists; if so, then open by Rush

Rush
Tue Jun 26 12:11:33 CDT 2007

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Paul Pedersen wrote:
<blockquote cite="mid:OSFs0ABuHHA.3476@TK2MSFTNGP02.phx.gbl" type="cite">
<pre wrap="">"Cy Welch" <a class="moz-txt-link-rfc2396E" href="mailto:cywelch@yahoo.com">&lt;cywelch@yahoo.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:umLd6W6tHHA.3588@TK2MSFTNGP06.phx.gbl">news:umLd6W6tHHA.3588@TK2MSFTNGP06.phx.gbl</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Paul Pedersen wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I do not believe that is the case. According to the documentation, FoxPro
searches its path only when a path is not specifically included in the
parameter passed to FILE().

Furthermore, that matches the results of my own testing. For instance,
FILE("myfolder1\myfolder2\myfile.txt") returns .F. even if the file
myfolder1\myfile.txt exists and is in the current path setting.

LOCFILE() does what you described, but it also will pop up a window
prompting the user to locate the file if it cannot be found.
</pre>
</blockquote>
<pre wrap="">Test by looking for a file in the root directory of ANY drive, and it will
look on the path because for some reason the programmers didn't consider a
drive letter without additional path (such as "c:" or "c:\") to be a path.
IIRC this is not new behavior but have been this way since at least FPD
2.0.
</pre>
</blockquote>
<pre wrap=""><!---->

Well, I didn't try that. But frankly, to keep files in a root directory
seems like a bad practice.
</pre>
</blockquote>
<br>
Perhaps the "root" directory is a network share or local data directory
assigned to a drive letter.<br>
<br>
&nbsp;- Rush<br>
<br>
</body>
</html>

Re: Determing if a table exists; if so, then open by Cy

Cy
Tue Jun 26 18:22:39 CDT 2007

Paul Pedersen wrote:
> "Cy Welch" <cywelch@yahoo.com> wrote in message
> news:umLd6W6tHHA.3588@TK2MSFTNGP06.phx.gbl...
>> Paul Pedersen wrote:
>>> I do not believe that is the case. According to the documentation, FoxPro
>>> searches its path only when a path is not specifically included in the
>>> parameter passed to FILE().
>>>
>>> Furthermore, that matches the results of my own testing. For instance,
>>> FILE("myfolder1\myfolder2\myfile.txt") returns .F. even if the file
>>> myfolder1\myfile.txt exists and is in the current path setting.
>>>
>>> LOCFILE() does what you described, but it also will pop up a window
>>> prompting the user to locate the file if it cannot be found.
>> Test by looking for a file in the root directory of ANY drive, and it will
>> look on the path because for some reason the programmers didn't consider a
>> drive letter without additional path (such as "c:" or "c:\") to be a path.
>> IIRC this is not new behavior but have been this way since at least FPD
>> 2.0.
>
>
> Well, I didn't try that. But frankly, to keep files in a root directory
> seems like a bad practice.
>
>
>
I would agree, however that doesn't change the issue with the function.
Additionally it could be the root of a share, which may not actually
be the root of a drive. Where this issue really comes/came in was when
checking for a file on a floppy disk, since typically directories were
not used on them, you were "not providing a path" and FP would check its
path and basically tell you that the file existed on the floppy if it
was on the path, even if it was NOT on the floppy.

--
Cy Welch
Senior Programmer
MetSYS Inc
http://www.metsysinc.com

Re: Determing if a table exists; if so, then open by tim_witort

tim_witort
Thu Jun 28 11:09:40 CDT 2007

Rush Strong seemed to utter in news:9Nbgi.3542$cV.1421@trnddc04:

> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <meta content="text/html;charset=ISO-8859-1"
> http-equiv="Content-Type">
> </head>
> <body bgcolor="#ffffff" text="#000000">
> Paul Pedersen wrote:
> <blockquote cite="mid:OSFs0ABuHHA.3476@TK2MSFTNGP02.phx.gbl"
> type="cite">
> <pre wrap="">"Cy Welch" <a class="moz-txt-link-rfc2396E"
> href="mailto:cywelch@yahoo.com">&lt;cywelch@yahoo.com&gt;</a> wrote
> in message
> <a class="moz-txt-link-freetext"
> href="news:umLd6W6tHHA.3588@TK2MSFTNGP06.phx.gbl">news:umLd6W6tHHA.3588@
> TK2MSFTNGP06.phx.gbl</a>...
> </pre>
> <blockquote type="cite">
> <pre wrap="">Paul Pedersen wrote:
> </pre>
> <blockquote type="cite">
> <pre wrap="">I do not believe that is the case. According to the
> documentation, FoxPro
> searches its path only when a path is not specifically included in the
> parameter passed to FILE().
>
> Furthermore, that matches the results of my own testing. For instance,
> FILE("myfolder1\myfolder2\myfile.txt") returns .F. even if the file
> myfolder1\myfile.txt exists and is in the current path setting.
>
> LOCFILE() does what you described, but it also will pop up a window
> prompting the user to locate the file if it cannot be found.
> </pre>
> </blockquote>
> <pre wrap="">Test by looking for a file in the root directory of
> ANY drive, and it will
> look on the path because for some reason the programmers didn't
> consider a drive letter without additional path (such as "c:" or "c:\")
> to be a path. IIRC this is not new behavior but have been this way
> since at least FPD 2.0.
> </pre>
> </blockquote>
> <pre wrap=""><!---->
>
> Well, I didn't try that. But frankly, to keep files in a root directory
> seems like a bad practice.
> </pre>
> </blockquote>
> <br>
> Perhaps the "root" directory is a network share or local data directory
> assigned to a drive letter.<br>
> <br>
> &nbsp;- Rush<br>
> <br>
> </body>
> </html>
>

Might want to turn off HTML, Rush. Can't make heads or
tails of your post.

-- TRW
_______________________________________
t i m . w i t o r t
_______________________________________

Re: Determing if a table exists; if so, then open by Rush

Rush
Thu Jun 28 14:15:21 CDT 2007


Tim Witort wrote:
> Rush Strong seemed to utter in news:9Nbgi.3542$cV.1421@trnddc04:
>
>
<html snip>

>
> Might want to turn off HTML, Rush. Can't make heads or
> tails of your post.
>
> -- TRW
> _______________________________________
> t i m . w i t o r t
> _______________________________________
>

Thanks, Tim - my bad.

- Rush