-
Nov 23rd, 2020, 10:54 AM
#1
Thread Starter
Lively Member
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
-
Nov 23rd, 2020, 07:29 PM
#2
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.
-
Nov 23rd, 2020, 09:06 PM
#3
Thread Starter
Lively Member
Re: Open File Explorer showing selected file or Search results?
Originally Posted by jmcilhinney
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.
-
Nov 23rd, 2020, 10:30 PM
#4
Re: Open File Explorer showing selected file or Search results?
Originally Posted by Mugsy323
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.
-
Nov 24th, 2020, 08:58 AM
#5
Thread Starter
Lively Member
Re: Open File Explorer showing selected file or Search results?
Originally Posted by jmcilhinney
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.
-
Nov 24th, 2020, 09:48 AM
#6
Re: Open File Explorer showing selected file or Search results?
Originally Posted by Mugsy323
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.
Originally Posted by Mugsy323
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.
-
Nov 24th, 2020, 10:47 AM
#7
Re: Open File Explorer showing selected file or Search results?
Originally Posted by Mugsy323
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
-
Nov 24th, 2020, 05:09 PM
#8
Thread Starter
Lively Member
Re: Open File Explorer showing selected file or Search results?
Originally Posted by techgnome
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|