Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute not opening correct folder 2

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
334
GB
Hello all

A field in MYTABLE is called QUOTEDEST which holds the path to the folder which stores any documentation in both .PDF and .DOC created (I've had much success with a previous thread here at
From a command button in the click event on a form, I am using the following in attempt to open and display a certain link folder to my record:

Code:
USE MYTABLE SHARED
GO mrecno && example 231

DECLARE INTEGER ShellExecute IN shell32.dll ;
  INTEGER hndWin, ;
  STRING cAction, ;
  STRING cFileName, ;
  STRING cParams, ;
  STRING cDir, ;
  INTEGER nShowWin

cFileName = "explorer"
cAction = "open"

cPath=ALLTRIM(QUOTEDEST)

ShellExecute(0,cAction,cFileName,cPath,"",1)

When I run the above, it opens the Windows "Documents" folder.

If I change the:

Code:
cPath=ALLTRIM(QUOTEDEST)

to the root folder

Code:
cPath="\myprogram"

As a test, it opens the folder \myprogram

Additionally, a manual attempt at

Code:
cPath="\myprogram\2022 quotes"

Also opens the correct folder

The folders in the field QUOTEDEST which look like this \myprogram\2022 quotes\9-2022 a sample quote and definitely exist.

Any suggestions please?

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Steve,

Just a guess .. I wonder if this is caused by the spaces in \myprogram\2022 quotes\9-2022 a sample quote. If so, the solution might be to actually pass the string in double-quotes, like this:

Code:
cPath=[[highlight #FCE94F]"[/highlight]] + ALLTRIM(QUOTEDEST) + [[highlight #FCE94F]"[/highlight]]

As I say, it's just a guess, so don't spend too much time on it.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Steve,

I've just tried my suggestion. It doesn't solve the problem. It seems to be OK to pass a string containing spaces (not surprising really).

I noticed that if you pass a path that doesn't exist, Explorer will open in the Documents folder, which is what you are seeing. You say that the path ( \myprogram\2022 quotes\9-2022 a sample quote) definitely exists. But are you sure that is exactly what your QUOTEDEST field contains? If there is a mismatch between the contents of the field and the actual folder name, it would explain the behaviour you are seeing.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
One more idea ...

Given that your aim is to open a folder within Windows Explorer, you don't need to specify explorer.exe as the file name. Just pass the directory that you want to open as the filename, and leave the cPath parameter blank. In other words:

Code:
cAction = "open"
cFileName =ALLTRIM(QUOTEDEST)
cPath = ""

ShellExecute(0,cAction,cFileName,cPath,"",1)

I don't know if that will solve the problem, but it's worth a try.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello Mike

Thank you for your suggestions.

I'll give these a try as soon as able and post back.

Much appreciated.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Hello again

So I tried your last suggested and success!

Code:
USE MYTABLE SHARED
GO mrecno

DECLARE INTEGER ShellExecute IN shell32.dll ;
  INTEGER hndWin, ;
  STRING cAction, ;
  STRING cFileName, ;
  STRING cParams, ;
  STRING cDir, ;
  INTEGER nShowWin

[b]cAction = "open"
cFileName =ALLTRIM(QUOTEDEST)
cPath = ""

ShellExecute(0,cAction,cFileName,cPath,"",1)[/b] 

CLOSE DATABASES
CLEAR
RETURN

Very much appreciated and perhaps this was a case of occam's razor!

Best wishes and stay safe.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Good to hear it's working, Steve. Thanks for letting me know.

One small point: As I expect you already know, you only need to execute the [tt]DECLARE INTEGER ShellExecute ...[/tt] statement once. You don't need to do it every time you call it. I usually do it near the start of the main program. That said, calling it multiple times does no harm, except for a very small - probably negligible - loss of memory each time.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top