Jump to content

How to select a file in Windows Explorer?


This topic is 4218 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a script that opens a folder on a network volume. The intention is to open the folder and attempt to select the file. If the file can't be selected, it's OK—I'm not going to bother the user with an error message. I have this working on the Mac side via AppleScript, but I can't get the file select portion working on Windows. Here are my relevant script steps:

#Folder was opened successfully - Now attempt to select the source file as a nicety

Set Variable [ $select_file_path; Value:$successful_url & $part_number & $part_revision & $file_extension ]

If [ Abs(Get(SystemPlatform)) = "1" ]

#Mac

Perform AppleScript [ Calculated AppleScript: "tell application "Finder"¶ reveal "" & $select_file_path & ""¶ end tell" ]

Set Variable [ $select_error; Value:Get(LastError) ]

Else

#Windows

// Open URL [ "explorer /select, "" & $select_file_path & """ ] [ No dialog ]

Send Event [ open document; "explorer.exe /select, "" & $select_file_path & """ ] [ Bring application to foreground ]

Set Variable [ $select_error; Value:Get(LastError) ]

Show Custom Dialog [ Title: "debug"; Message: "Error: " & $select_error & "¶" & "explorer.exe /select, "" & $select_file_path & """; Buttons: “OK” ]

End If

The $select_error returns 0 on Windows, but the file is still not selected in the folder that opens up. Here is the exact error message (screenshot attachment upload isn't working):


Error: 0

explorer.exe /select, "10.0.0.19LSI Engineering017-XXXX-XXXX-XX017-0000-XXXX-XX017-0000-02XX-XX017-0000-0266-00.eps"

Am I right in using the Send Event script step? I saw in another thread that one could use cmd /c del to delete a file, but I couldn't find an appropriate command to select a file ("goto" doesn't seem to be right).

Link to comment
Share on other sites

If the file is not being selected, you do not have the correct path/filename/extension. The /select switch you have used, IS the proper syntax to select the file, if it exists, using explorer.exe.

Note, however, that the way you have it written, the Explorer window will not come to the foreground, even though you have [bring Application to Foreground]. In this particular case, with explorer.exe, to bring the explorer.exe instance to the foreground, the entire command must be prefixed with CMD or preferrably CMD /C, e.g. CMD /C explorer.exe /select, "path_and_filename.ext". Try Start|CMD and pasting the command into a DOS Window first. If you do not prefix with CMD, the explorer instance will still open, it just won't be in foreground.

Unfortunately, Send Event will not report errors; Get(LastError) only reports errors originating in Filemaker. This is why it always reports zero, even if the command you send, has errors. So this logic won't work.

Thus, you must test for file's existence, prior to running Send Event. This can be done by attempting to import it and trapping the error if not found, use of MooPlug, ScriptMaster, or numerous other means. If you want to import it then it needs to go into a container since that will be capable of displaying the EPS image. If file can't be found, you may want it to just open the directory file was supposed to be in.

I recently did some work with MS Access, one feature I liked, was the ability to drag/drop files to table & retrieve their name/path using VBA.

Link to comment
Share on other sites

This topic is 4218 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.