[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] 求修改:拖到这里选定文件.bat,谢谢

拖到这里选定文件.bat:
  1. ::【拖到这里选定文件】
  2. @echo off
  3. explorer /select,%~1
  4. exit
复制代码
将文件拖到批处理图标,会(在新窗口)打开文件所在目录,并且选定这个文件
*******************************************************
现在希望:将文件拖到批处理图标,在原来窗口(不打开新窗口)选定这个文件


谢谢
我是小白,希望老师多多帮助

拖到这里选定文件.bat:将文件拖到批处理图标,会(在新窗口)打开文件所在目录,并且选定这个文件
****** ...
yyz219 发表于 2022-12-30 16:31



    是不是不能够解决?
我是小白,希望老师多多帮助

TOP

搜一下排第一个的就是呀
  1. #@&cls&powershell "$a='%~1';type '%~f0'|out-string|iex"&exit
  2. add-type @'
  3. using System;
  4. using System.IO;
  5. using System.Text;
  6. using System.Runtime.InteropServices;
  7. using System.Diagnostics;
  8. using System.ComponentModel;
  9. public static class test
  10. {
  11.    [DllImport("shell32.dll", ExactSpelling = true)]
  12.     private static extern void ILFree(IntPtr pidlList);
  13.     [DllImport("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
  14.     private static extern IntPtr ILCreateFromPathW(string pszPath);
  15.     [DllImport("shell32.dll", ExactSpelling = true)]
  16.     private static extern int SHOpenFolderAndSelectItems(IntPtr pidlList, uint cild, IntPtr children, uint dwFlags);
  17.     public static void ExplorerFile(string filePath)
  18.     {
  19.         if (!File.Exists(filePath) && !Directory.Exists(filePath))
  20.             return;
  21.         if (Directory.Exists(filePath))
  22.             Process.Start(@"explorer.exe", "/select,\"" + filePath + "\"");
  23.         else
  24.         {
  25.             IntPtr pidlList = ILCreateFromPathW(filePath);
  26.             if (pidlList != IntPtr.Zero)
  27.             {
  28.                 try
  29.                 {
  30.                     Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0));
  31.                 }
  32.                 finally
  33.                 {
  34.                     ILFree(pidlList);
  35.                 }
  36.             }
  37.         }
  38.     }
  39. }
  40. '@
  41. [test]::ExplorerFile($a)
复制代码
1

评分人数

TOP

搜一下排第一个的就是呀
idwma 发表于 2023-1-1 18:00



    感谢你的帮助
我是小白,希望老师多多帮助

TOP

搜一下排第一个的就是呀
idwma 发表于 2023-1-1 18:00



    一.有一点慢
    二、对桌面的文件,还是会在新窗口打开再选定

有没有办法修改一下?谢谢
我是小白,希望老师多多帮助

TOP

powershell第一次启动是有一点慢的
两个桌面的路径不一样,这个不会改呀

TOP

powershell第一次启动是有一点慢的
两个桌面的路径不一样,这个不会改呀
idwma 发表于 2023-1-1 18:23



    谢谢
我是小白,希望老师多多帮助

TOP

返回列表