Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Temp files
Message
From
28/09/1997 12:44:22
Larry Long
ProgRes (Programming Resources)
Georgia, United States
 
 
To
28/09/1997 01:38:05
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Title:
Miscellaneous
Thread ID:
00051865
Message ID:
00052068
Views:
33
>>I have a foxpro 2.5b application that uses the Sys(3) function to create temporary databases and
>>text files. When I create an updated version of the exe file and place it into an existing application's
>>directory, I get error messages that a temp file, ex 54909706.txt, already exists. When this happens,
>>there are no previous temp files in the directory and I can see this new file in the directory
>>because the application just created it. Is there anyway that the Foxpro ESL library file is
>>storing this number twice when trying to assign a unique one?
>
>Glen,
> Pat Adams wrote a routine a while back to generate random file names that I believe combined the 1st 4 chars from sys(3) and the last 4 chars from a sys(16), to create a more random filename..
>
>I can lookup the routine for you if you like..
>
>Thanx!
>
>Tony Miller
>Vancouver, Wa

The sys(3) function, in part, relies on the system clock. So if your machine is "fast enough", the sys(3) function does return duplicates. I have a program called uniqfile.prg that ensures that the file created is, in fact unique. What is does is check for the exsitence of the file, then when there is none, it actually creates a 0 byte file with the new name, so that it "reserves" that name, just in case someone else is running the same app somewhere else.

UNIQFILE.PRG (needs a dummy dbf called UNIQTEST.DBF)
-------------------------

PARAMETERS PREFIX,EXT
* Author: Larry Alan Long / Copyright 1997, All rights reserved.
* Freeware, you may distribute, use and modify this code as you see fit. Just keep the comment section intact along with
* documenting any changes that you have added.
*
* Parameters - PREFIX - For naming your temp files with a specified prefix. I use this so you can track where the temp files
* come from if your app does not clean up properly after itself and you wind up with temp
* files cluttering up your system.
* - EXT - For naming your temp file's extension
*
* For example, I would use UNIFILE('RIX','TMP') to create a temp file called RIX00001.TMP, for my reindexing routine.
*
IF EMPTY(PREFIX)
STORE SPACE(0) TO PREFIX
ENDIF

IF EMPTY(EXT)
STORE "TMP" TO EXT
ENDIF

STORE ON('ERROR') TO olderrproc

ON ERROR DO UNIQERR

*To prevent a possible duplicate, UNIQTEST.DBF is a dummy dbf that is used to ensure that only one
* UNIQFILE is generated at a time.

USE UNIQTEST EXCLUSIVE IN 0

ON ERROR &olderrproc

STORE 1 TO TRIES

DO WHILE TRIES<=100

STORE PREFIX+RIGHT(SYS(3),8-LEN(PREFIX))+'.'+EXT TO UNIQFILE

IF ! FILE(UNIQFILE)
XX=FCREATE(UNIQFILE)
=FCLOSE(XX)
EXIT
ENDIF

STORE TRIES+1 TO TRIES
ENDDO

USE IN UNIQTEST


IF TRIES>100
WAIT WINDOW 'TOO MANY TRIES. SOMETHING IS WRONG!'
RETURN(.F.)
ENDIF

RETURN(UNIQFILE)

PROCEDURE UNIQERR
WAIT WINDOW "WAITING FOR PROCESS TO BE RELEASED BY ANOTHER" TIMEOUT 1
WAIT CLEAR
RETRY
RETURN
L.A.Long
ProgRes
lalong1@charter.net
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform