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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am using ShellExecute(0,'open',m.lcFolder,'','',1) to display files

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi Again,
I have this code, to display files from a folder but i need to display the files as details, instead of listing or tiles or whatever else, i just need them to be displayed as Details, any sugestions, this codes resides in the Command click of a Button

Local lcFolder
lcFolder = Alltrim(Thisform.txtfolder.Value)
If !Empty(m.lcFolder)
ShellExecute(0,'open',m.lcFolder,'','',1)
Else
Messagebox('Please select the folder you want to view first!',64,'Opppppssss!')
Endif

Thanks
 
Even if you simply use the GetFile() function the dialogs appear in the form the user wants. This is a Windows standard. I don't know a way to determine the type of file display as detail list, but the user can choose whatever he likes best.

Bye, Olaf.
 
You can't do this with ShellExecute(). That's because there is no command-line switches that control the "view" setting in Windows Explorer.

However, you can do it with the Windows Scripting Object. It's a bit more complicated, but the following will give you a rough idea. Essentially, the aim is to launch Windows Explorer, and then send keystrokes needed to it to put it into Details view.

Code:
DECLARE Sleep IN WIN32API INTEGER iPeriod
oWsh = CREATEOBJECT("wscript.shell")
oWsh.Run("Explorer", 1)   && launches Explorer and brings it to the front
Sleep(500)                && wait while the program is being launched
oWsh.SendKeys("%v")       && send Alt+V (to open the View menu)
Sleep(500)                && wait for that to happen
oWsh.SendKeys("d")        && send "d" to select "Display"

The above assumes that your version of Windows Explorer has the traditional View menu. I have't checked this with the latest versions of Windows. But it's the general principle that I am showing here. Adapt it as needed.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
On Win7 I don't see a hotkey for the choice of view. I can test on Win8 tomorrow.

Bye, Olaf.
 
On my Windows 7 system, I see the same View menu as on earlier versions. So Alt+V,D does work. But I don't know if that's the default setup, or if I did something specific to configure it that way.

That said, I'm inclined to agree with you, Olaf, when you say that it should be up to the user to decide which view to use.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I can surely imagine you want to list details, file size, date in some situations. Then you may use ADIR and display the result array in a listbox or grid. There even is a very legacy style rowsourcetype=7 for the listbox to show files. I wouldn't recommend it.

Bye, Olaf.
 
If the View menu is not present, an alternative series of keystrokes would be something like:

[tt]TAB[/tt] (to get to the right-hand pane), [tt]Shift+F10[/tt] (to open the context menu), and [tt]Alt+v d[/tt] to select Details view.

So the SendKeys() call could be:

[tt]oWsh.SendKeys("{TAB}+{F10}vi")[/tt]

But remember, as with any technique that depends on a given series of keystrokes, the keys might change with future versions of Windows, or with the way in which the user's system is configured.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,

I suppose the code:

oShell = CREATEOBJECT("Wscript.Shell")
oShell.SendKeys("+{TAB}+{F10}{DOWN}{ENTER}{ENTER}{ENTER}{ENTER}{ENTER}{ENTER}")
=GETPICT("JPG")

will open the directory with a list and details.

Jockey(2)
 
Hello Mike,

this code do the works but where in the code i pass the parameter to open the folder i want ?
cause when i use it, like is below , this opens explorer in "My documents" and not the folder i selected from the getdir(), in the line below you will see the variable, that should have the value passed by getdir(), which is "m.lcFolder" so where in your code, i should insert m.lcFolder ?

ShellExecute(0,'open',m.lcFolder,'','',1) && this code open the explorer in the folder i select from getdir() but do not show it as Details, your code below does, but i need to insert somewhere in your code "m.lcFolder" to display the files from the folder i selected previously in Details.


Your code:
DECLARE Sleep IN WIN32API INTEGER iPeriod
oWsh = CREATEOBJECT("wscript.shell")
oWsh.Run("Explorer", 1) && launches Explorer and brings it to the front
Sleep(500) && wait while the program is being launched
oWsh.SendKeys("{TAB}+{F10}vi") && send Alt+V (to open the View menu)
Sleep(500) && wait for that to happen
oWsh.SendKeys("d") && send "d" to select "Display"

Thanks
 
The code I gave you was just meant to give you the general ideal. I assumed you would be able to fine-tune it to do exactly what you want.

In general, you can pass the name of an "object" (file, folder, etc.) to Explorer to have it focus on that object. Also pass [tt]/e[/tt] or [tt]/n[/tt] to open in either "Explorer" view (with the folder tree in the sidebar) or single-pane view. So the following might give you want you want:

[tt]oWsh.Run("Explorer /e,/select,c:\work", 1)[/tt]

(Assuming you have a folder named Work on your c: drive.)

Or, try changing /e to /n.

Another option would be simply to pass the folder name:

[tt]oWsh.Run("c:\work")[/tt]

Do any of those give you what you want?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
I have a button that execute this first to select the folder i want
Code:
LOCAL lcFolder
lcFolder = GETDIR()
IF !EMPTY(m.lcFolder)
   SET DEFAULT TO (m.lcFolder)
   thisform.txtFolder.Value = m.lcFolder
ENDIF


Then another button to execute the below code, after i already selected the folder from the above code.

Notice here what i commented and i did that cause your code allow me to see DETAILS, while the commented one allow me to display the content of the folder but not as Details, so i am using your code but it is not taking me to the folder selected in the above code, so i need, to know how can i pass the value of the variable "m.lcFolder" to your code to open explorer on that folder value contained in "m.lcFolder"
Code:
Local lcFolder
lcFolder = Alltrim(Thisform.txtfolder.Value)
If !Empty(m.lcFolder)
 *ShellExecute(0,'open',m.lcFolder,'','',1) 
	
	
DECLARE Sleep IN WIN32API INTEGER iPeriod
oWsh = CREATEOBJECT("wscript.shell")
oWsh.Run("Explorer",1)   && launches Explorer and brings it to the front
Sleep(500)                && wait while the program is being launched
oWsh.SendKeys("{TAB}+{F10}vi") && send Alt+V (to open the View menu)
Sleep(500)                && wait for that to happen
oWsh.SendKeys("d") 	
	
Else
	Messagebox('Please select the folder you want to view first!',64,'Opppppssss!')
Endif


Thanks
 
Did you not see my previous post? I gave you several options that I think will give you what you want. You just have to change your call to [tt]oWsh.Run[/tt].

If none of those work, you might check this page, which gives you all the command-line paramters for launching the Explorer window: Command-Line Switches for Windows Explorer

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Now, having said all that, I have to question your overall approach. You seem to be expecting the user first to use the standard Directory dialogue to choose a directory, and you then want to open Explorer with that directory in focus. And, if the user fails to choose the directory first, you don't open Explorer, but instead issue a message to tell them to go back to the Directory dialogue.

Wouldn't it be simpler just to open the Explorer window and let them navigate to the folder in question? It's no more work for the user than having to drill down into the Directory dialogue, and it would make your coding a lot simpler.

At the very least, why do you need two buttons to do the job? Even if you do keep the separate Directory dialogue, why not put that in the same button as the opening of the Explorer window? That would eliminate the possiblity of the user not doing things in the right order, and would avoid the need for the error message.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
When using the "Select" option of the "EXPLORER" followed by the m.lcfolder(WHICH IS THE "sub_object"), i am geting error message as m.lcfolder does not exist, i checked that the value in m.lcfolder exist but probably the syntax is wrong in the below line

/select,<sub object> this the option i am using


oWsh.Run("Explorer /e,/select,m.lcfolder", 1) this is what i addded, is this the correct syntax ?

and i checked, that it is a value in m.lcfolder, why then i am getting error "the path'(m.lcfolder)' does not exist or is not a directory"
Thanks a lot
 
No, that won't work. That's because lcFolder is a Visual Foxpro variable, and Windows Explorer doesn't know anything about it. You will have to pass the actual folder name. Something like this:

[tt]oWsh.Run("Explorer /e,/select," + ALLTRIM(m.lcfolder), 1)[/tt]

Give that a try.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Michel,
That is working cause explorer now goes and highlite the folder but it does not open it, to display the files inside it and for hence as they are not displayed then there is not way to make these lines to so their job

oWsh.SendKeys("{TAB}+{F10}vi") && send Alt+V (to open the View menu)
Sleep(500) && wait for that to happen
oWsh.SendKeys("d")

Thanks a lot

 
Yes i did, and i get an error " ole the system cannot find the specified file, at least with the previous line code, it select the folder but stay there highlited which in this case the user will need to double click the folder to open it and display the files and besides that they won't display as "DETAILS", I don't see any other switch to "open" the specified folder from the path that is storage in m.lcfolder
Thanks
 
If you have reached a position where the user can double-click on a folder to open it, then it follows that the user can also press Enter to open it. That in turns means that you can use SendKeys to send an Enter key. So just add {ENTER} to the end of your existing keystroke string, and that should work.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

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

Part and Inventory Search

Sponsor

Back
Top