HB_DirTemp

HB_DirTemp

Returns name of temp dir of system / user, with closing backslash

Syntax

      HB_DirTemp() -> <SysTempDirName>

Argument

None

Result

<SysTempDirName> : name of temp dir of system / user

Description

HB_DirTemp() is an environment function to obtain name of temp dir of system / user.

This info can be get by SET TEMP command in cmd box and by GETE() function also (see example).

Note that Harbour add a dir-separator (backslash for Windows) to end of <SysTempDirName>.

In Windows, this is : C:\Users\<CurrentUser>\AppData\Local\Temp

Example

      ? HB_DirTemp()
      ? GETE( 'TEMP' )

Seealso

GETE(), GETENV(), HB_GetEnv()

HB_FTempCreateEx

HB_FTempCreateEx

Creates and opens a temporary file.

Syntax

HB_FTempCreateEx( @<cFileName,;
                    <cTempDir>,;
                    <cPrefix>,;
                    <cFileExtension> --> <nFileHandle>

Arguments

 @<cFileName> :must be passed by reference. It receives the file name of the created temporary  file as a character string.

<cTempDir> : A character string specifying the directory where to create the temporary file. It defaults to the operating       system variable SET TEMP or SET TMP. Operating system variables can be queried with function HB_GetEnv().

<cPrefix> : A character string of three characters specifying the prefix to use for the name of the temporary file. It defaults  to the string “hb”.

<nFileExtension> : A character value specifying extension of the temporary file.

Returns

<nFileHandle> : a numeric value > 0 when the temporary file is successfully created. This is the file handle of the created temporary file.

Description

Function HB_FTempCreateEx() creates a temporary file and opens it. The return value is the file handle of the temporary file. It can be used with low level file functions, such as FWrite() to store data in the file. Temporary files are often required in an application.

HB_FTempCreateEx() guarantees that the file name of the newly created file is unique, so that no existing file will be overwritten. To obtain the file name of the temporary file, parameter <cFileName> must be passed by reference. It can then later be passed to function FErase() in order to remove the temporary file from disk.

HB_FTempCreateEx() is similar to HB_FTempCreate(), but allows to control the extension. Note, that the ordering of parameters had slightly changed compared to hb_fsCreateTemp().

Example

      PROC TestHBFTempEx()

         LOCAL nFileHandle
         LOCAL cFileName

         nFileHandle := HB_FTempCreateEx( @cFileName,;   // File Name
                                          ,;             // <cTempDir>
                                          ,;             // <cPrefix>
                                          '.tmp' )       // file extension

         IF nFileHandle > 0
            ? 'Temp file builded with name :', cFileName
            WAIT
            FClose( nFileHandle )
            FErase( cFileName )
         ELSE
            ALERT( "Couldn't build temp file"  )
         ENDI

      RETU // TestHBFTempEx()

Seealso

TempFile(), HB_FTempCreate(), FCreate(), FErase(), FWrite(), HB_GetEnv()

TempFile

TempFile

Creates a file for temporary use

Syntax

      TempFile([<cDirectory>], [<cExtension>], [<nFileAttr>])
             --> <cFileName>

Arguments

<cDirectory> : The drive and directory where the temporary file is to be created. The default is the system/user temp directory.

<cExtension> : The file extension for the file. The default is no extension.

<nFileAttr> : A file attribute for the file.

Returns

<cFileName> : The name of the temporary file. If no file is created, the function returns a null string.

Description

If you only need a file for a short time and want to avoid conflicts with existing files, use TempFile() to create a file with a unique name. Names created by TempFile() use the system date and system time. You can hide the file, if you specify an attribute. Attributes are coded as follows:

         File Attribute Coding
         ------------------------------------------------------------------------
         Value   Symb. constants     Definition
         ------------------------------------------------------------------------
         0       FA_NORMAL
         1       FA_READONLY         READ ONLY
         2       FA_HIDDEN           HIDDEN (Hidden files)
         4       FA_SYSTEM           SYSTEM (System files)
         32      FA_ARCHIVE          ARCHIVE (Changed since last backup)
         ------------------------------------------------------------------------

Notes

. The temporary file name is always 8 characters long and consists exclusively of numbers with a period, if no extension has been specified. The file is created with a length of 0 bytes.

Examples

      .  Create a temporary file in the system/user temp  directory:

         cTempFile := TempFile()

      .  Create a temporary file in the root directory of the E: drive:

         cTempFile := TempFile("E:\")

      .  Create a temporary file with a .TMP extension and a HIDDEN
         attribute in the root directory of the C: drive:

         cTempFile := TempFile("C:\", "TMP", 2)

Seealso

HB_FTempCreate(), HB_FTempCreateEx(), FCreate(), FErase(), FWrite(), HB_GetEnv()

hb_GetEnv()

HB_GETENV()

Obtains a system environmental setting.

Syntax

      HB_GETENV(<cEnviroment>, [<cDefaultValue>], [<lApplyCodepage>] )
                   --> <cReturn>

Arguments

<cEnviroment> Enviromental variable to obtain.

<cDefaultValue> Optional value to return if <cEnvironment> is not found.

<lApplyCodepage> optional logical parameter specifing whether to apply automatic codepage conversion (to the codepage specified by Set( _SET_OSCODEPAGE ) on the obtained value. The default is .T. Note that if the default value is passed and the environment value is not found, this codepage conversion is not performed against the returned default value

Returns

<cReturn> Value of the environment variable or <cDefaultValue> or an empty string.

Description

This function yields a string that is the value of the environment variable <cEnviroment>, which is stored at the system level.

If no environment variable can be found, the value of the function will be <cDefaultValue> if it is passed, else an empty string.

Examples

      ? HB_GETENV( "PATH" )
      ? HB_GETENV( "CONFIG" )
      ? HB_GETENV( "HARBOURCMD", "-n -l -es2" )

Compliance

Harbour

Platforms

All

Files

src/rtl/gete.c Library is rtl

Seealso

GETENV, GETE

GetEnv()

Template

Function

Name

GetEnv()

Category

API

Subcategory

Environment

Oneliner

Obtains a system environmental setting.

Syntax

      GetEnv( <cEnviroment> )  --> <cReturn>

Arguments

<cEnviroment> Enviromental variable to obtain.

Returns

<cReturn> Value of the Environment Variable.

Description

This function yields a string that is the value of the environment variable <cEnviroment>, which is stored at the system level.

If no environment variable is found, an empty string is returned.

Examples

      ? GetEnv( "PATH" )
      ? GetEnv( "CONFIG" )
      ? GetEnv( "HARBOURCMD",  "-n -l -es2" )

Compliance

Clipper

Platforms

All

Files

Library is core

Seealso

GetE()