Re: Try/Catch handling of Copy File errors

2007-07-03 Thread Justin Darnell
Why not just check to see if the file exists first using something like

IF !FILE(DestinationName)
COPY FILE  TO 
ELSE
 *Whatever, log error, etc..
ENDIF

All wrapped up in your try catch?

Justin

On 7/2/07, Joe Yoder <[EMAIL PROTECTED]> wrote:
>
> I need to copy a file from one directory to another.  I use the COPY FILE
>  TO  inside the Try/Catch structure.
>
> When  does not exist, Catch gets control and all is well.
>
> When  does not exist, Catch gets control and all is well.
>
> When  already exists, I get an Interactive Message Box
> reporting that fact and asking what to do.  Catch does not get control so
> there is a problem as this applications needs to run unattended!
>
> Does anyone know whether this behavior is by design and if so - why?  Any
> workarounds?
>
> Thanks - Joe
>
>
>
> --- StripMime Report -- processed MIME parts ---
> multipart/alternative
>   text/plain (text body -- kept)
>   text/html
> ---
>
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Try/Catch handling of Copy File errors

2007-07-03 Thread Kevin Cully
Can you do a FILE() before attempting to copy the file?

lcTargetFile = "c:\test\target.dbf"
IF FILE(lcTargetFile)
  && Log that the file already exists
ELSE
  TRY
COPY FILE (lcSourceFile) TO (lcTargetFile)
  CATCH
&& Log problem of copying file.
  ENDTRY
ENDIF

I've been using the COPYFILE from the WIN32API because it is faster than
the VFP based COPY FILE command.  It might be worth looking into.  I'm a
 WebConnect customer so they have that in the wwAPI class.

HTH.

-Kevin
CULLY Technologies, LLC

Sponsor of FoxForward 2007
foxforward.net


Joe Yoder wrote:
> I need to copy a file from one directory to another.  I use the COPY FILE 
>  TO  inside the Try/Catch structure.
>  
> When  does not exist, Catch gets control and all is well.
>  
> When  does not exist, Catch gets control and all is well.
>  
> When  already exists, I get an Interactive Message Box 
> reporting that fact and asking what to do.  Catch does not get control so 
> there is a problem as this applications needs to run unattended!
>  
> Does anyone know whether this behavior is by design and if so - why?  Any 
> workarounds?
>  
> Thanks - Joe
>  
> 
> 
> --- StripMime Report -- processed MIME parts ---
> multipart/alternative
>   text/plain (text body -- kept)
>   text/html
> ---
> 
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


RE: Try/Catch handling of Copy File errors

2007-07-03 Thread Tracy Pearson
It's by design, and can be avoided with SET SAFETY OFF.
This will overwrite the existing file without the interactive dialog.

Tracy

-Original Message-
From: Joe Yoder
Sent: Monday, July 02, 2007 11:41 AM

I need to copy a file from one directory to another.  I use the COPY FILE
 TO  inside the Try/Catch structure.
 
When  does not exist, Catch gets control and all is well.
 
When  does not exist, Catch gets control and all is well.
 
When  already exists, I get an Interactive Message Box
reporting that fact and asking what to do.  Catch does not get control so
there is a problem as this applications needs to run unattended!
 
Does anyone know whether this behavior is by design and if so - why?  Any
workarounds?
 
Thanks - Joe
 



___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Try/Catch handling of Copy File errors

2007-07-03 Thread Paul Newton
Joe

What is your SET SAFETY setting ?  Does it make a difference ?

Paul Newton

Joe Yoder wrote:
> I need to copy a file from one directory to another.  I use the COPY FILE 
>  TO  inside the Try/Catch structure.
>  
> When  does not exist, Catch gets control and all is well.
>  
> When  does not exist, Catch gets control and all is well.
>  
> When  already exists, I get an Interactive Message Box 
> reporting that fact and asking what to do.  Catch does not get control so 
> there is a problem as this applications needs to run unattended!
>  
> Does anyone know whether this behavior is by design and if so - why?  Any 
> workarounds?
>  
> Thanks - Joe
>  
>
>
> --- StripMime Report -- processed MIME parts ---
> multipart/alternative
>   text/plain (text body -- kept)
>   text/html
> ---
>
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


re: Try/Catch handling of Copy File errors

2007-07-03 Thread Joe Yoder
Thanks to all who responded.

My use at this point is to create unique filenames on a server in a 
bulletproof way.  I rejected the approach of testing for file existence 
before creation because multiple programs running create a (very slight) 
chance that two instances will attempt to create a file with the same 
name at the same time.

It is possible to reliably create the file by setting safety off but this 
does not protect against a second program's using the same name and 
overwriting the information written by the first.

I posted the question partly because the Try/Catch approach is new to me. 
 It looks great but it doesn't seem to completely handle the first thing 
I tried to use it for.  Tracy says the behavior is by design.  My 
question is why is it designed this way and is there some logic that will 
define what the other commands or conditions are that will not be trapped 
by Catch?

I think I can achieve what I need by looping FCREATE() until 
success.  At that point I will have the name of a file I can safely 
overwrite by setting safety off.

The API approach is something I would like to know more about.  Where 
does one get a list of what is available?

Thanks,

Joe
 
On Tuesday, July 03, 2007  9:04 AM, Kevin Cully wrote:
>
>Date: Tue, 03 Jul 2007 09:04:00 -0400
>From: Kevin Cully
>To: [EMAIL PROTECTED]
>Subject: Re: Try/Catch handling of Copy File errors
>
>Can you do a FILE() before attempting to copy the file?
>
>lcTargetFile = "c:\test\target.dbf"
>IF FILE(lcTargetFile)
>  && Log that the file already exists
>ELSE
>  TRY
>COPY FILE (lcSourceFile) TO (lcTargetFile)
>  CATCH
>&& Log problem of copying file.
>  ENDTRY
>ENDIF
>
>I've been using the COPYFILE from the WIN32API because it is faster than
>the VFP based COPY FILE command.  It might be worth looking into.  I'm a
> WebConnect customer so they have that in the wwAPI class.
>
>HTH.
>
>-Kevin
>CULLY Technologies, LLC
>
>Sponsor of FoxForward 2007
>foxforward.net
>
>
>Joe Yoder wrote:
>> I need to copy a file from one directory to another.  I use the COPY FILE 
>>  TO  inside the Try/Catch structure.
>>
>> When  does not exist, Catch gets control and all is well.
>>
>> When  does not exist, Catch gets control and all is well.
>>
>> When  already exists, I get an Interactive Message Box 
>> reporting that fact and asking what to do.  Catch does not get control so 
>> there is a problem as this applications needs to run unattended!
>>
>> Does anyone know whether this behavior is by design and if so - why?  Any 
>> workarounds?
>>
>> Thanks - Joe
>>
>>
>>
>> --- StripMime Report -- processed MIME parts ---
>> multipart/alternative
>>   text/plain (text body -- kept)
>>   text/html
>> ---
>>
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Try/Catch handling of Copy File errors

2007-07-03 Thread Kevin Cully
Rick Strahl sells a product called Web Connection.  Here's the
documentation on the wwAPI class.

http://west-wind.com/webconnection/docs/_0pa1bhnlp.htm

-Kevin
CULLY Technologies, LLC

Sponsor of FoxForward 2007
foxforward.net


Joe Yoder wrote:
> The API approach is something I would like to know more about.  Where 
> does one get a list of what is available?



___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Try/Catch handling of Copy File errors

2007-07-03 Thread Ted Roche
On 7/3/07, Joe Yoder <[EMAIL PROTECTED]> wrote:

> I think I can achieve what I need by looping FCREATE() until
> success.  At that point I will have the name of a file I can safely
> overwrite by setting safety off.

There's a windows API call. I think it's CreateTemporaryFileName()
that does exactly this. Limited to 65,535 files iirc.

Nope, a quick Google shows GetTemporaryFileName. Here's the VB
knowledgebase article:

http://support.microsoft.com/kb/195763

-- 
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com


___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Try/Catch handling of Copy File errors

2007-07-03 Thread Paul Newton
Joe Yoder wrote:
> Thanks to all who responded.
>
> My use at this point is to create unique filenames on a server in a 
> bulletproof way. 
How about an approach based on GUIDs:

The *CoCreateGuid* function may be used when it is necessary to obtain 
an absolutely unique number that will be used as a persistent identifier 
in a distributed environment. To a very high degree of certainty, this 
function returns a unique value: that is, no other invocation, on the 
same or any other system (networked or not), should return the same value.

See

 
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q269/3/87.asp&NoWebContent=1


Paul Newton



___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


re: Try/Catch handling of Copy File errors

2007-07-03 Thread Joe Yoder
That would be an option except that my application needs 8 character file 
names.

Thanks,

Joe

On Tuesday, July 03, 2007  3:57 PM, Paul Newton wrote:
>
>Date: Tue, 03 Jul 2007 20:57:55 +0100
>From: Paul Newton
>To: [EMAIL PROTECTED]
>Subject: Re: Try/Catch handling of Copy File errors
>
>Joe Yoder wrote:
>> Thanks to all who responded.
>>
>> My use at this point is to create unique filenames on a server in a
>> bulletproof way.
>How about an approach based on GUIDs:
>
>The *CoCreateGuid* function may be used when it is necessary to obtain
>an absolutely unique number that will be used as a persistent identifier
>in a distributed environment. To a very high degree of certainty, this
>function returns a unique value: that is, no other invocation, on the
>same or any other system (networked or not), should return the same value.
>
>See
>
> http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q269/3/87.asp&NoWebContent=1
>
>
>Paul Newton
>
>
>
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


re: Try/Catch handling of Copy File errors

2007-07-03 Thread Joe Yoder
Thanks - Maybe some day I'll take the time to try to use this.

Joe

On Tuesday, July 03, 2007  2:46 PM, Ted Roche wrote:
>
>Date: Tue, 3 Jul 2007 14:46:11 -0400
>From: Ted Roche
>To: [EMAIL PROTECTED]
>Subject: Re: Try/Catch handling of Copy File errors
>
>On 7/3/07, Joe Yoder <[EMAIL PROTECTED]> wrote:
>
>> I think I can achieve what I need by looping FCREATE() until
>> success.  At that point I will have the name of a file I can safely
>> overwrite by setting safety off.
>
>There's a windows API call. I think it's CreateTemporaryFileName()
>that does exactly this. Limited to 65,535 files iirc.
>
>Nope, a quick Google shows GetTemporaryFileName. Here's the VB
>knowledgebase article:
>
>http://support.microsoft.com/kb/195763
>
>--
>Ted Roche
>Ted Roche & Associates, LLC
>http://www.tedroche.com
>
>
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Try/Catch handling of Copy File errors

2007-07-03 Thread Eugene Vital
Joe Yoder wrote:
> Thanks - Maybe some day I'll take the time to try to use this.
>
>   

Couldn't you just have a table for storing the last used file name and
auto increment it ;)?

 



> Joe
>
> On Tuesday, July 03, 2007  2:46 PM, Ted Roche wrote:
>   
>> Date: Tue, 3 Jul 2007 14:46:11 -0400
>> From: Ted Roche
>> To: [EMAIL PROTECTED]
>> Subject: Re: Try/Catch handling of Copy File errors
>>
>> On 7/3/07, Joe Yoder <[EMAIL PROTECTED]> wrote:
>>
>> 
>>> I think I can achieve what I need by looping FCREATE() until
>>> success.  At that point I will have the name of a file I can safely
>>> overwrite by setting safety off.
>>>   
>> There's a windows API call. I think it's CreateTemporaryFileName()
>> that does exactly this. Limited to 65,535 files iirc.
>>
>> Nope, a quick Google shows GetTemporaryFileName. Here's the VB
>> knowledgebase article:
>>
>> http://support.microsoft.com/kb/195763
>>
>> --
>> Ted Roche
>> Ted Roche & Associates, LLC
>> http://www.tedroche.com
>>
>>
>> 
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


re: Try/Catch handling of Copy File errors

2007-07-03 Thread Joe Yoder

On Tuesday, July 03, 2007  8:05 PM, Eugene Vital wrote:

Couldn't you just have a table for storing the last used file name and
auto increment it ;)?

That is what I would do if my program was the only one writing to the 
directory.  There are potentially other programs creating files there as 
well.  I'm guessing the others would probably use the API approach so it 
would make sense to do that but I don't have the time available to learn 
how to do it that way. - Joe 
>
>
>
>
>> Joe
>>
>> On Tuesday, July 03, 2007  2:46 PM, Ted Roche wrote:
>>
>>> Date: Tue, 3 Jul 2007 14:46:11 -0400
>>> From: Ted Roche
>>> To: [EMAIL PROTECTED]
>>> Subject: Re: Try/Catch handling of Copy File errors
>>>
>>> On 7/3/07, Joe Yoder <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>> I think I can achieve what I need by looping FCREATE() until
>>>> success.  At that point I will have the name of a file I can safely
>>>> overwrite by setting safety off.
>>>>
>>> There's a windows API call. I think it's CreateTemporaryFileName()
>>> that does exactly this. Limited to 65,535 files iirc.
>>>
>>> Nope, a quick Google shows GetTemporaryFileName. Here's the VB
>>> knowledgebase article:
>>>
>>> http://support.microsoft.com/kb/195763
>>>
>>> --
>>> Ted Roche
>>> Ted Roche & Associates, LLC
>>> http://www.tedroche.com
>>>
>>>
>>>
[excessive quoting removed by server]

___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.


Re: Try/Catch handling of Copy File errors

2007-07-04 Thread Ted Roche
On 7/3/07, Joe Yoder <[EMAIL PROTECTED]> wrote:
>
> That is what I would do if my program was the only one writing to the
> directory.  There are potentially other programs creating files there as
> well.  I'm guessing the others would probably use the API approach so it
> would make sense to do that but I don't have the time available to learn
> how to do it that way. - Joe

It's amazing how much time you've spent not learning how to use the
API calls, just in posting messages here.

It's a four-line function you add to your application, plus a bit of
error-trapping and call it with:

lcMyNewTempFileName = GTFN()

Here's my original program that does something a bit different from
what you're trying to do. See if you can adapt it for your needs.
Don't hesitate to ask questions.



* Program: GTFN.PRG

* Version: 1.0

* Author.: Ted Roche

* Date...: October 11, 1999

* Notice.: Copyright (c) 1999 Ted Roche

* Compiler...: Visual FoxPro 06.00.8492.00 for Windows

* Abstract...: Wrapper for GetTempFileName() API call

* Parameters.: None

* Returns: Ted001.tmp, tedoo2.tmp

* Changes: Should be parameterized to accept the three-letter

* .0.: prefix, return error codes?





LPARAMETERS tcPathName

DECLARE INTEGER GetTempPath IN WIN32API ;

INTEGER BufferLength, ;

STRING Buffer



DECLARE INTEGER GetTempFileName IN WIN32API ;

STRING  Pathname, ;

STRING  Prefix, ;

INTEGER nUnique, ;

STRING  TempFileName



local lcPath, lnPath, lnReturn, lcFileName



lnPath = 254

STORE REPL(CHR(0), lnPath) to lcPath, lcFileName



IF TYPE("tcPathName") <> "C" OR ;

   NOT(DIRECTORY(tcPathName))  && parameter omitted or invalid

   * Create the path from the WinAPI call

   IF GetTempPath(lnPath, @lcPath) = 0

 RETURN ""  && couldn't create path; bail

   ENDIF

ELSE

  * It's valid, assign the passed parameter

  lcPath = tcPathname

ENDIF



IF GetTempFileName(lcPath, ;   && path

   "Ted" , ;   && Prefix

   0 , ;   && Actually create the file

   @lcFileName) ;

   = 0  && function failed

   RETURN ""

ELSE

  lcFileName = LEFT(lcFileName, AT(CHR(0),lcFileName)-1 )

ENDIF



RETURN lcFileName


"Any society that would give up a little liberty to gain a little
security will deserve neither and lose both" -- Benjamin Franklin

-- 
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com


___
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.