RANDOM FileName ?

Post Reply
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

RANDOM FileName ?

Post by Jimmy »

hi,

i know

Code: Select all | Expand

GetTempFileName( LPCSTR tmpdir, LPCSTR prefix, UINT unique, LPSTR filename )

but it seems not available under harbour :(

did somebody have made a HB_FUNC( GetTempFileName ) and can share it :?:

p.s. need "A" and/or "W" Function
greeting,
Jimmy
User avatar
Enrico Maria Giordano
Posts: 8767
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: RANDOM FileName ?

Post by Enrico Maria Giordano »

Try cNewFileName() or cTempFile(). Look at source\function\filename.prg.
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: RANDOM FileName ?

Post by Jimmy »

hi,
Enrico Maria Giordano wrote:Try cNewFileName() or cTempFile(). Look at source\function\filename.prg.

Ok,
Thx for Answer
greeting,
Jimmy
User avatar
carlos vargas
Posts: 1723
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RANDOM FileName ?

Post by carlos vargas »

Code: Select all | Expand

#include "fileio.ch"

FUNCTION TempFile( cDir, cExt, nAttr )

   LOCAL cName
   LOCAL fhnd

   IF HB_ISSTRING( cDir )
      cDir := hb_DirSepAdd( cDir )
   ENDIF

   IF HB_ISSTRING( cExt ) .AND. !( Left( cExt, 1 ) == "." )
      cExt := "." + cExt
   ENDIF

   hb_default( @nAttr, SetFCreate() )

   fhnd := hb_FTempCreateEx( @cName, cDir,, cExt, nAttr )

   IF fhnd != F_ERROR
      FClose( fhnd )
      RETURN cName
   ENDIF

   RETURN ""
 

this function, exist in in hbct lib, please try
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: RANDOM FileName ?

Post by Jimmy »

hi
carlos vargas wrote:this function, exist in in hbct lib, please try

Aha, OK
Thx for Advice
greeting,
Jimmy
User avatar
Rick Lipkin
Posts: 2674
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RANDOM FileName ?

Post by Rick Lipkin »

Been using this for years ... not complicated ..



Code: Select all | Expand



cDEFA :="C"

DO WHILE .T.
   SITEDBF := "TEMP"+(SUBSTR(TIME(),7,2)+SUBSTR(TIME(),4,2))
   IF .not. FILE( cDefa+"\DBTMP\"+SITEDBF+".DBF" )
      EXIT
   ENDIF
ENDDO




Rick Lipkin
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: RANDOM FileName ?

Post by Jimmy »

hi,
Rick Lipkin wrote:Been using this for years ... not complicated ..

Yes,
i have use something like this as Workaround.

Code: Select all | Expand

cFile := "T"+DTOS(Date())+STRZERO(Seconds(),5)+".TXT"
greeting,
Jimmy
User avatar
Otto
Posts: 6413
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 27 times
Been thanked: 2 times
Contact:

Re: RANDOM FileName ?

Post by Otto »

Dear Antonio,
can you please show how we can include this API function?

I tried different ways, but I am missing something. I get errors.

Best regards,
Otto

These are my tests:

Code: Select all | Expand




function main


/*
UINT GetTempFileNameA(
  [in]  LPCSTR lpPathName,
  [in]  LPCSTR lpPrefixString,
  [in]  UINT   uUnique,
  [out] LPSTR  lpTempFileName
);
*/

? GetTmpFileName('c:\fwh\samples\',"ABC","123")

DLL32 Function GetTmpFileName  (  lpszPath As String,   lpPrefixString As String,   wUnique As Long,   lpTempFileName As String) As Long PASCAL ;
FROM "GetTempFileNameA" LIB "kernel32.dll"


 /*
 
 #pragma BEGINDUMP

#include <stdio.h>
#include <hbapi.h>
#include <windows.h>

HB_FUNC( GETTEMPFILENAMEA )
{
     
  hb_retl( GetTempFileNameA( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ) ) );
}
 

#pragma ENDDUMP

//----------------------------------------------------------------------------//
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: RANDOM FileName ?

Post by Antonio Linares »

Dear Otto,

Using dynamic linking:

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

  local cFileName := Space( 50 )

  /*
  UINT GetTempFileNameA(
    [in]  LPCSTR lpPathName,
    [in]  LPCSTR lpPrefixString,
    [in]  UINT   uUnique,
    [out] LPSTR  lpTempFileName
  );
  */


  GetTmpFileName( 'c:\fwh\samples', "ABC", 0, @cFileName )

  MsgInfo( cFileName )

return nil  

DLL32 Function GetTmpFileName( lpszPath AS LPSTR, lpPrefixString AS LPSTR, nUnique AS LONG, @lpTempFileName AS LPSTR ) AS LONG PASCAL ;
   FROM "GetTempFileNameA" LIB "kernel32.dll"


Using static linking: (in this case we directly return the created name)

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

  local cFileName := Space( 50 )

  /*
  UINT GetTempFileNameA(
    [in]  LPCSTR lpPathName,
    [in]  LPCSTR lpPrefixString,
    [in]  UINT   uUnique,
    [out] LPSTR  lpTempFileName
  );
  */


  ? GetTmpFileName( 'c:\fwh\samples', "ABC", 0, @cFileName )

return nil  

// DLL32 Function GetTmpFileName( lpszPath AS LPSTR, lpPrefixString AS LPSTR, nUnique AS LONG, @lpTempFileName AS LPSTR ) AS LONG PASCAL ;
//    FROM "GetTempFileNameA" LIB "kernel32.dll"

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( GETTMPFILENAME )
{
   char * cFileName = ( char * ) hb_xgrab( 50 );  
 
   GetTempFileNameA( hb_parc( 1 ), hb_parc( 2 ), hb_parnl( 3 ), cFileName );
   hb_retc( cFileName );
   hb_xfree( cFileName );
}

#pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 6413
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 27 times
Been thanked: 2 times
Contact:

Re: RANDOM FileName ?

Post by Otto »

Dear Antonio,
thank you so much.


Best regards,
Otto
PS; Have you seen the email from Renate?
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: RANDOM FileName ?

Post by Antonio Linares »

Dear Otto,

I haven't got any email from her

Please send your family my best regards
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: RANDOM FileName ?

Post by nageswaragunupudi »

Windows API function GetTempFileName() always uses ".TMP" extension.
FWH functions are better.
Regards

G. N. Rao.
Hyderabad, India
Post Reply