function that return the temp directory of the logged user
-
- Posts: 22
- Joined: Fri Nov 04, 2005 9:05 pm
- Location: LIEGE Belgium
function that return the temp directory of the logged user
I am looking for the instruction that return the path of the temp directory
win2000 and WinXp
(c:\documents and settings\user1\.....)
Thanks
Philippe Jacquet
win2000 and WinXp
(c:\documents and settings\user1\.....)
Thanks
Philippe Jacquet
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
-
- Posts: 22
- Joined: Fri Nov 04, 2005 9:05 pm
- Location: LIEGE Belgium
Thanks a lot
Thans
Philippe Jacquet
Philippe Jacquet
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Philippe,
Enrico's solution won't always work. Here is a more comprehensive solution.
James
Enrico's solution won't always work. Here is a more comprehensive solution.
James
Code: Select all
//--- Returns temporary directory name without trailing backslash
function getTempDir()
local cDir := GetEnv("TEMP")
if empty(cDir)
cDir := GetEnv("TMP")
endif
if Right( cDir, 1 ) == "\"
cDir := SubStr( cDir, 1, Len( cDir ) - 1 )
endif
if !empty(cDir)
if !lIsDir(cDir)
cDir := GetWinDir()
endif
else
cDir := GetWinDir()
endif
return cDir
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
Hi James.
I think your code is incomplete.
It may so occur that there are defined two variables TEMP and TMP in environment. For example TEMP=C:\TEMP and TMP=C:\TMP while directory C:\TEMP does not exist but directory C:\TMP does exist.
In this case I think directory C:\TMP should be used instead of GetWinDir().
Vladimir Grigoriev
I think your code is incomplete.
It may so occur that there are defined two variables TEMP and TMP in environment. For example TEMP=C:\TEMP and TMP=C:\TMP while directory C:\TEMP does not exist but directory C:\TMP does exist.
In this case I think directory C:\TMP should be used instead of GetWinDir().
Vladimir Grigoriev
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
Maybe something as the following
//--- Returns temporary directory name without trailing backslash
function GetTempDir()
local cTargetDir, cTempDir, cTmpDir
local lTempExist, lTmpExist
cTempDir := GetEnv( "TEMP" )
cTmpDir := GetEnv( "TMP" )
if ( Right( cTempDir, 1 ) == "\" )
cTempDir := SubStr( cTempDir, 1, Len( cTempDir ) - 1 )
endif
if ( Right( cTmpDir, 1 ) == "\" )
cTmpDir := SubStr( cTmpDir, 1, Len( cTmpDir ) - 1 )
endif
lTempExist := .F.
if ( !empty( cTempDir ) )
if ( IsDir(cTempDir ) )
lTempExist := .T.
endif
endif
lTmpExist := .F.
if ( !empty( cTmpDir ) )
if ( IsDir(cTmpDir ) )
lTmpExist := .T.
endif
endif
do case
case ( lTempExist )
cTargetDir := cTempDir
case ( lTmpExist )
cTargetDir := cTmpDir
otherwise
cTargetDir := GetWinDir()
endcase
return ( cTargetDir )
//--- Returns temporary directory name without trailing backslash
function GetTempDir()
local cTargetDir, cTempDir, cTmpDir
local lTempExist, lTmpExist
cTempDir := GetEnv( "TEMP" )
cTmpDir := GetEnv( "TMP" )
if ( Right( cTempDir, 1 ) == "\" )
cTempDir := SubStr( cTempDir, 1, Len( cTempDir ) - 1 )
endif
if ( Right( cTmpDir, 1 ) == "\" )
cTmpDir := SubStr( cTmpDir, 1, Len( cTmpDir ) - 1 )
endif
lTempExist := .F.
if ( !empty( cTempDir ) )
if ( IsDir(cTempDir ) )
lTempExist := .T.
endif
endif
lTmpExist := .F.
if ( !empty( cTmpDir ) )
if ( IsDir(cTmpDir ) )
lTmpExist := .T.
endif
endif
do case
case ( lTempExist )
cTargetDir := cTempDir
case ( lTmpExist )
cTargetDir := cTmpDir
otherwise
cTargetDir := GetWinDir()
endcase
return ( cTargetDir )
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
Also the statement
if ( Right( cTempDir, 1 ) == "\" )
cTempDir := SubStr( cTempDir, 1, Len( cTempDir ) - 1 )
endif
is not correct enough.
The following would be more correct.
if ( ( Right( cTempDir, 1 ) == "\" ) .AND. ! ( Right( cTempDir, 2 ) == ":\" ) )
cTempDir := SubStr( cTempDir, 1, Len( cTempDir ) - 1 )
endif
Vladimir Grigoriev
if ( Right( cTempDir, 1 ) == "\" )
cTempDir := SubStr( cTempDir, 1, Len( cTempDir ) - 1 )
endif
is not correct enough.
The following would be more correct.
if ( ( Right( cTempDir, 1 ) == "\" ) .AND. ! ( Right( cTempDir, 2 ) == ":\" ) )
cTempDir := SubStr( cTempDir, 1, Len( cTempDir ) - 1 )
endif
Vladimir Grigoriev
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Enrico,
Yea, like Valdimir says, thats too easy.
I suppose if getEnv("TEMP") returns a blank string then any temp files will just be written to the current directory. There probably won't be any error message. I'm not saying there is anything wrong with that, just that you probably wouldn't know if it was not working as expected.
James
Yea, like Valdimir says, thats too easy.
I suppose if getEnv("TEMP") returns a blank string then any temp files will just be written to the current directory. There probably won't be any error message. I'm not saying there is anything wrong with that, just that you probably wouldn't know if it was not working as expected.
James
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
-
- Posts: 54
- Joined: Fri Oct 21, 2005 10:45 am
- Location: Russia, Moscow
- Contact:
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact: