Results 1 to 8 of 8

Thread: Open File Explorer showing selected file or Search results?

  1. #1

    Thread Starter
    Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    32

    Question Open File Explorer showing selected file or Search results?

    I want to open the File Explorer so it highlights a specific file (or shows the results of a search.)

    I can open the FE easily using:

    Code:
    System.Diagnostics.Process.Start("explorer.exe", My.Computer.FileSystem.GetParentPath(myFile))
    ...which opens the FE at a specific location (the "System.Diagnostics." prefix opens a new Explorer window in case the FE is already running.)

    But I don't want to show ALL of the contents at that location, just files ending in ".bkp" (adding it to the path doesn't work.)

    Is there an easy way to do this? (If the solution requires more than 3 lines of code, don't bother. it's not that important.)

    TIA

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,099

    Re: Open File Explorer showing selected file or Search results?

    If it's possible then it's not really anything to do with VB. It will be done via a commandline argument to the explorer.exe executable, so you should research what arguments are available. Whatever you can do will be the same as what you can do from an actual command window. If there is something, you will incorporate it into the second argument to Process.Start, which is the commandline arguments for the new process.

    That said, maybe you should be using an OpenFileDialog or SaveFiileDialog instead. It depends on exactly what you're trying to accomplish but those dialogues will allow you to filter the files displayed by extension.

  3. #3

    Thread Starter
    Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    32

    Re: Open File Explorer showing selected file or Search results?

    Quote Originally Posted by jmcilhinney View Post
    That said, maybe you should be using an OpenFileDialog or SaveFiileDialog instead.
    Thx for the reply.

    I have a program than on rare occasion crashes if the file it is trying to rename is found to be "in use". No way to avoid it. And when it happens, the file is somehow wiped out. I have yet to figure out why (How is an "in use" file hard deleted?)

    So I create a backup just before the rename function and "Try" to rename. If I "Catch" a crash, I wish to open File Explorer showing the backup file.

    Not a big deal though. Instead, I'll probably just rename the file back and warn the user the program can't continue until the conflict is resolved. It's such a rare error, it's almost not worth the trouble.

    Thx again.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,099

    Re: Open File Explorer showing selected file or Search results?

    Quote Originally Posted by Mugsy323 View Post
    If I "Catch" a crash
    That is a contradiction in terms. You catch exceptions and your application crashes if an exception is thrown and goes uncaught. If an exception is thrown and you catch it then, by definition, there is no crash.

  5. #5

    Thread Starter
    Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    32

    Re: Open File Explorer showing selected file or Search results?

    Quote Originally Posted by jmcilhinney View Post
    That is a contradiction in terms. You catch exceptions and your application crashes if an exception is thrown and goes uncaught. If an exception is thrown and you catch it then, by definition, there is no crash.
    W/o the Try/Catch, it crashes. If I try to continue afterwards, it crashes.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,099

    Re: Open File Explorer showing selected file or Search results?

    Quote Originally Posted by Mugsy323 View Post
    W/o the Try/Catch, it crashes.
    That would be because an exception is thrown. Like I said, a crash is an unhandled exception. If you catch the exception then there is no crash.
    Quote Originally Posted by Mugsy323 View Post
    If I try to continue afterwards, it crashes.
    That would be because a different exception is being thrown later. If you try to execute some code and an exception is thrown then carrying on as though the code executed successfully will likely throw another exception because the application is not what you're assuming it to be. For instance, if you try to save data to a file but the save fails and an exception is thrown, the app will crash right there if you don't catch. If you do catch it but you carry on as though the save succeeded and later try to read the file then an exception will be thrown there. Proper programming technique requires you to guard all code that could throw an exception with an exception handler and, if an exception is thrown, act in later code with that in mind.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,155

    Re: Open File Explorer showing selected file or Search results?

    Quote Originally Posted by Mugsy323 View Post
    I have a program than on rare occasion crashes if the file it is trying to rename is found to be "in use". No way to avoid it. And when it happens, the file is somehow wiped out. I have yet to figure out why (How is an "in use" file hard deleted?)
    Easy... the file is in use at the time you tried to access it... between the time you accessed it, and you go looking for it, the owning process is done with it and cleaned up after itself and deleted the file... or, it was already in the process of trying to delete it when you tried to move it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    32

    Re: Open File Explorer showing selected file or Search results?

    Quote Originally Posted by techgnome View Post
    Easy... the file is in use at the time you tried to access it... between the time you accessed it, and you go looking for it, the owning process is done with it and cleaned up after itself and deleted the file... or, it was already in the process of trying to delete it when you tried to move it.

    -tg
    No. The "owning process" is my app. Once my app ends, the file is released.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width