Create a unique filename

This forum is for eXpress++ general support.
Post Reply
Message
Author
unisoft
Posts: 7
Joined: Thu Mar 26, 2015 4:24 am

Create a unique filename

#1 Post by unisoft »

Hello,

Any one has a small function to create a unique filename ? similar to sys(3)

Regards

Koverhage
Posts: 151
Joined: Mon Feb 01, 2010 8:45 am

Re: Create a unique filename

#2 Post by Koverhage »

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

User avatar
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

#3 Post by Eugene Lutsenko »

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.

User avatar
Tom
Posts: 1199
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Create a unique filename

#4 Post by Tom »

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."

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Create a unique filename

#5 Post by Victorio »

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"

unisoft
Posts: 7
Joined: Thu Mar 26, 2015 4:24 am

Re: Create a unique filename

#6 Post by unisoft »

Thank you All.

User avatar
rdonnay
Site Admin
Posts: 4762
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Create a unique filename

#7 Post by rdonnay »

pomdbf1s:=cestatlac+"P"+padl(alltrim(str(int(seconds()) )),8,"0")+alltrim(str(RandomInt(1000,9999)))+".DBF"
I use a similar function, but I start with today's date.
This will insure that there can be no duplicate.
The eXpress train is coming - and it has more cars.

Post Reply