RANDOM FileName ?

RANDOM FileName ?

Postby Jimmy » Sat Aug 13, 2022 12:23 am

hi,

i know
Code: Select all  Expand view  RUN
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
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: RANDOM FileName ?

Postby Enrico Maria Giordano » Sat Aug 13, 2022 8:37 am

Try cNewFileName() or cTempFile(). Look at source\function\filename.prg.
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: RANDOM FileName ?

Postby Jimmy » Sun Aug 14, 2022 5:21 pm

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

Ok,
Thx for Answer
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: RANDOM FileName ?

Postby carlos vargas » Mon Aug 15, 2022 4:35 pm

Code: Select all  Expand view  RUN
#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
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RANDOM FileName ?

Postby Jimmy » Mon Aug 15, 2022 7:28 pm

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

Aha, OK
Thx for Advice
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: RANDOM FileName ?

Postby Rick Lipkin » Mon Aug 15, 2022 7:32 pm

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



Code: Select all  Expand view  RUN


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
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RANDOM FileName ?

Postby Jimmy » Mon Aug 15, 2022 7:39 pm

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

Yes,
i have use something like this as Workaround.
Code: Select all  Expand view  RUN
cFile := "T"+DTOS(Date())+STRZERO(Seconds(),5)+".TXT"
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: RANDOM FileName ?

Postby Otto » Tue Aug 16, 2022 5:58 am

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 view  RUN



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
Otto
 
Posts: 6340
Joined: Fri Oct 07, 2005 7:07 pm

Re: RANDOM FileName ?

Postby Antonio Linares » Tue Aug 16, 2022 6:23 am

Dear Otto,

Using dynamic linking:
Code: Select all  Expand view  RUN
#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 view  RUN
#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
Antonio Linares
Site Admin
 
Posts: 42121
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: RANDOM FileName ?

Postby Otto » Tue Aug 16, 2022 7:44 am

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
Otto
 
Posts: 6340
Joined: Fri Oct 07, 2005 7:07 pm

Re: RANDOM FileName ?

Postby Antonio Linares » Tue Aug 16, 2022 7:03 pm

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
Antonio Linares
Site Admin
 
Posts: 42121
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: RANDOM FileName ?

Postby nageswaragunupudi » Tue Aug 16, 2022 8:17 pm

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 25 guests