Hello,
Any one has a small function to create a unique filename ? similar to sys(3)
Regards
Create a unique filename
Re: Create a unique filename
Do you mean a function like this ?
Code: Select all
FUNCTION GetTempFileName_a(cPfad)
Local nDll, cRetVal := space(260), nRetVal := 0, nUnique := 0, cPrefix := "TFX"
nDll := DllLoad( "KERNEL32.DLL")
IF nDll != 0
nRetVal := DllCall( nDll, DLL_STDCALL, "GetTempFileNameA", ;
cPfad, @cPrefix, nUnique, @cRetVal )
DllUnload( nDll )
ENDIF
RETURN substr(cRetVal, 1, At(Chr(0),cRetVal)-1 )
Klaus
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: Create a unique filename
I would use data from a computer timer like this to form a unique file name: mFileName = ALLTRIM(STR((DOY(DATE())-1)*86400+SECONDS()))
Last edited by Eugene Lutsenko on Sun Jun 24, 2018 8:00 am, edited 1 time in total.
Re: Create a unique filename
TempFile() will create a filename unique for the directory you use as a parameter. If you want to create a filename which is unique for the whole world, use UuidToChar(UuidCreate()). This will create a unique string (also very handy for unique IDs without the need of counter files and stuff like this) which can be used as a filename.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Re: Create a unique filename
I see, this is many handy functions, I use seconds and random() function ,
str(seconds())+randomint() like this
pomdbf1s:=cestatlac+"P"+padl(alltrim(str(int(seconds()) )),8,"0")+alltrim(str(RandomInt(1000,9999)))+".DBF"
str(seconds())+randomint() like this
pomdbf1s:=cestatlac+"P"+padl(alltrim(str(int(seconds()) )),8,"0")+alltrim(str(RandomInt(1000,9999)))+".DBF"
Re: Create a unique filename
I use a similar function, but I start with today's date.pomdbf1s:=cestatlac+"P"+padl(alltrim(str(int(seconds()) )),8,"0")+alltrim(str(RandomInt(1000,9999)))+".DBF"
This will insure that there can be no duplicate.
The eXpress train is coming - and it has more cars.