1

I need to get certain special windows folders in Windows 10 from a TD 6.3 program - for instance, Program Files, user, or Appdata. Is there a certain function for this? I've looked through the help but can't seem to find it.

I also need to check if the program currently has read/write access to a folder I specify. I suspect the latter can be achieved by trying a SalFileOpen or SalFileWrite respectively and checking the result.

The point is that I need to get some temporary files from a network location to the local machine to be able to use them, as I only have read access to the network drive. As of now I've simply created a temp folder in C:\, this works perfectly in debug, but when I build the program and then try running it, for some reason it doesn't get the files and the temp folder stays empty. Thinking this was a permission issue, I tried running as admin to no avail. I'm kind of at a loss as to why it won't work, so any input is appreciated. I simply copy the needed files from the network drive to the temp folder using SalFileCopy with the overwrite flag set to true.

Skjoldson
  • 41
  • 4

2 Answers2

1

You can use windows API-functions for that. To get the temp-path you can use the following: Define an external function:

Kernel32.dll
Function: GetTempPathW
Return
    DWORD
Parameters:
    Number: DWORD    ! nBufferLength [in] The size of the string buffer identified by lpBuffer, in TCHARs.
    Receive String: LPWSTR    ! lpBuffer [out] A pointer to a string buffer that receives the null-terminated string

Use it like that:

Function: GetTempPath           ! __exported
    Description: WinAPI: This function retrieves the path of the directory designated for temporary files.
    Returns
        String:
    Parameters
    Local variables
        String: sStrBuffer
        Number: nBuffLen
        Number: nNumChars
    Actions
        Set nBuffLen = 0
        Call SalSetBufferLength( sStrBuffer, nBuffLen )
        Set nBuffLen = GetTempPathW( nBuffLen, sStrBuffer )
        Call SalSetBufferLength( sStrBuffer, nBuffLen * 2 )
        Call GetTempPathW( nBuffLen, sStrBuffer )
        If SalStrRightX( sStrBuffer, 1 ) != '\\'
            Set sStrBuffer = sStrBuffer || '\\'
        Return sStrBuffer

To check if you have write access just create a file in that folder and delete it afterwards.

Here some more info about the windows API-function: https://msdn.microsoft.com/de-de/library/windows/desktop/aa364992(v=vs.85).aspx

1

In case you need any path of the environment variables (e.g. appdata) you can use

VisDosGetEnvString( 'appdata' )

The method is part of the Visual Tool Chest (vt.apl lib within the installation dir)

Bonus
  • 31
  • 3