In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Creating unique temporary files

Xailer professional forum in English
g.s.rogers
Mensajes: 202
Registrado: Dom Feb 17, 2008 3:35 am

Creating unique temporary files

Mensaje por g.s.rogers »

Does anyone have suggestions for the best way to create unique temporary
files? I am working on a networked application and need to create temporary
databases for reports. Because several clients may attempt to run these
reports at the same time, the temporary files need to have unique names.
I tried to use code like the following that worked in Clipper:
FUNCTION UniqFile
LOCAL I, FHandle
LOCAL cFileName := ""
I := 0
DO WHILE .T.
cFileName := 'TMP'+leadchar(STR(I,5,0),'0')+'.'+cExtension
IF ! FILE(cFileName) // if file doesn't already exist
// have to actually create a file in order to reserve its name
// the parameter 0 signifies file is created with normal attributes
(read/write)
IF FHandle := FCREATE(cFileName,0) < 0
msgStop("Unable to create temporary file.")
ENDIF
EXIT
ELSE
I := I + 1
ENDIF
ENDDO
RETURN cFileName
However, I find that on a workstation running Vista, I get a DOS 32 error
whenever attempting to overwrite a file created in this manner. For
instance, if I create a temporary file named TMP00000.TMP, assign it to the
memvar cFile1 and then try the statement CREATE &cFile1, I get a DOS ERROR
32. DOS Error 32 is a "sharing violation". My existing uniqfile function has
to actually create the file in order to reserve that unique filename for
future use -- it cannot just give me a potential file name to use later with
a CREATE statement because I don't know if that filename will still be
unique at a future time later in the code execution. FCREATE has no problem
creating the file, but even though it has created it with the "Normal"
attribute (READ/WRITE), xHarbour apparently can't overwrite it in Vista. I'm
thinking Vista must handle file creation and manipulation differently than
XP because my app never had a problem with this code on XP workstations.
Any suggestions would be appreciated.
Thanks in advance,
Gary
Responder