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.

Reply via email to