在与其父文件夹相同的 window 中查看子文件夹?
View a subfolder in the same window as its parent?
我有一个父文件夹,它包含子文件夹和其他文件(文本文件、图像、可执行文件..),它们都放在同一路径中(实际上,这是它们父文件夹的路径)。
SendKeys.SendWait("sub");
SendKeys.SendWait("{ENTER}");
以上两行执行了我需要的操作;它在其父文件夹视图的相同 window 中打开名为 'sub' 的文件夹,而不打开新文件夹。(图片显示了我想避免的情况,假设我想找到执行 "selecting" 子文件夹的等效操作的最佳方法,然后按 ENTER 在相同的 window 中打开它,而不启动单独的和新的)
有什么建议吗?我在 ShellExecuteA() 中读到了默认动词,但这似乎对我不起作用;我的代码是
using System.Runtime.InteropServices;
namespace testFaza
{
class Program
{
[DllImport("shell32.dll")]
static extern int ShellExecuteA(int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
static void Main(string[] args)
{
string path = @"sub\";
ShellExecuteA(0, null, path, null, null, 1);
}
}
}
当我释放的时候,然后执行的时候,输出结果就像第一张图:
编辑:
string path = @"sub\";
dynamic ws = Microsoft.VisualBasic.Interaction.CreateObject("WScript.Shell");
ws.Run("explorer.exe /select, " + (char)34 + path + (char)34);
然后按 SendKey 按 {ENTER},这是我迄今为止遇到的最佳解决方案。
Explorer.exe 支持 /SELECT 的命令行参数,这将 select files/folders,例如子文件夹:
string sPath = "c:\bin\release\sub";
//Start a Window and reliably select a subfolder
Process.Start("explorer.exe", " /select," & sPath);
//Open the folder
SendKeys.SendWait("{ENTER}");
我有一个父文件夹,它包含子文件夹和其他文件(文本文件、图像、可执行文件..),它们都放在同一路径中(实际上,这是它们父文件夹的路径)。
SendKeys.SendWait("sub");
SendKeys.SendWait("{ENTER}");
以上两行执行了我需要的操作;它在其父文件夹视图的相同 window 中打开名为 'sub' 的文件夹,而不打开新文件夹。(图片显示了我想避免的情况,假设我想找到执行 "selecting" 子文件夹的等效操作的最佳方法,然后按 ENTER 在相同的 window 中打开它,而不启动单独的和新的)
有什么建议吗?我在 ShellExecuteA() 中读到了默认动词,但这似乎对我不起作用;我的代码是
using System.Runtime.InteropServices;
namespace testFaza
{
class Program
{
[DllImport("shell32.dll")]
static extern int ShellExecuteA(int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
static void Main(string[] args)
{
string path = @"sub\";
ShellExecuteA(0, null, path, null, null, 1);
}
}
}
当我释放的时候,然后执行的时候,输出结果就像第一张图:
编辑:
string path = @"sub\";
dynamic ws = Microsoft.VisualBasic.Interaction.CreateObject("WScript.Shell");
ws.Run("explorer.exe /select, " + (char)34 + path + (char)34);
然后按 SendKey 按 {ENTER},这是我迄今为止遇到的最佳解决方案。
Explorer.exe 支持 /SELECT 的命令行参数,这将 select files/folders,例如子文件夹:
string sPath = "c:\bin\release\sub";
//Start a Window and reliably select a subfolder
Process.Start("explorer.exe", " /select," & sPath);
//Open the folder
SendKeys.SendWait("{ENTER}");