cTempFile() -> bad alias
Posted: Wed May 31, 2006 3:59 pm
if you use cTempFile( cPath, 'DBF') to create temporary dbf file then the all numeric tempfile will cause an "illegal characters in alias" error when used.
I would use cNewFileName() but I need to create temp file using path.
Also I found that if you need a couple of temp files then you need to run cTempFile(), then create the actual file before you can get another temporary file with cTempFile().
This is especially true with cNewFileName()
I would like to change cTempFile so that it adds an alpha to the beginning of filename, or add path option to cNewFileName()
Something like:
function cTempFile( cPath, cExtension ) // returns a temporary filename
local cFileName
static cOldName
DEFAULT cPath := "", cExtension := ""
if ! "." $ cExtension .and. .not. empty( cExtension )
cExtension = "." + cExtension
endif
// Added 'A' to filename but we could pass a cRootName also
while File( cFileName := ( cPath + 'A'+StrTran( Time(), ":", "" ) + cExtension ) ) .or. ;
cFileName == cOldName
end
cOldName = cFileName
return cFileName
// and / or
//---------------------------------------------------------------------------//
function cNewFileName( cRootName, cExt, cPath )
local cFileName := cRootName + "1"
local nId := 1
static cOldName
DEFAULT cPath := ""
if ! "." $ cExtension .and. .not. empty( cExtension )
cExtension = "." + cExtension
endif
cFileName += cExtension
while File( cPath+cFileName ) .or. ;
cFileName == cOldName
cFileName = cRootName + ;
StrZero( ++nId, If( nId < 10, 1,;
If( nId < 100, 2, 3 ) ) ) + ;
cExt
end
cOldName = cFileName
return cFileName
I would use cNewFileName() but I need to create temp file using path.
Also I found that if you need a couple of temp files then you need to run cTempFile(), then create the actual file before you can get another temporary file with cTempFile().
This is especially true with cNewFileName()
I would like to change cTempFile so that it adds an alpha to the beginning of filename, or add path option to cNewFileName()
Something like:
function cTempFile( cPath, cExtension ) // returns a temporary filename
local cFileName
static cOldName
DEFAULT cPath := "", cExtension := ""
if ! "." $ cExtension .and. .not. empty( cExtension )
cExtension = "." + cExtension
endif
// Added 'A' to filename but we could pass a cRootName also
while File( cFileName := ( cPath + 'A'+StrTran( Time(), ":", "" ) + cExtension ) ) .or. ;
cFileName == cOldName
end
cOldName = cFileName
return cFileName
// and / or
//---------------------------------------------------------------------------//
function cNewFileName( cRootName, cExt, cPath )
local cFileName := cRootName + "1"
local nId := 1
static cOldName
DEFAULT cPath := ""
if ! "." $ cExtension .and. .not. empty( cExtension )
cExtension = "." + cExtension
endif
cFileName += cExtension
while File( cPath+cFileName ) .or. ;
cFileName == cOldName
cFileName = cRootName + ;
StrZero( ++nId, If( nId < 10, 1,;
If( nId < 100, 2, 3 ) ) ) + ;
cExt
end
cOldName = cFileName
return cFileName