找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 17398|回复: 6

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

[复制链接]
发表于 2022-12-30 16:31:26 | 显示全部楼层 |阅读模式
拖到这里选定文件.bat:

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


谢谢
 楼主| 发表于 2023-1-1 17:35:47 | 显示全部楼层
拖到这里选定文件.bat:将文件拖到批处理图标,会(在新窗口)打开文件所在目录,并且选定这个文件
****** ...
yyz219 发表于 2022-12-30 16:31



    是不是不能够解决?
发表于 2023-1-1 18:00:11 | 显示全部楼层
搜一下排第一个的就是呀
  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技术 +1 收起 理由
yyz219 + 1 乐于助人

查看全部评分

 楼主| 发表于 2023-1-1 18:13:03 | 显示全部楼层
搜一下排第一个的就是呀
idwma 发表于 2023-1-1 18:00



    感谢你的帮助
 楼主| 发表于 2023-1-1 18:18:22 | 显示全部楼层
搜一下排第一个的就是呀
idwma 发表于 2023-1-1 18:00



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

有没有办法修改一下?谢谢
发表于 2023-1-1 18:23:47 | 显示全部楼层
powershell第一次启动是有一点慢的
两个桌面的路径不一样,这个不会改呀
 楼主| 发表于 2023-1-1 18:37:02 | 显示全部楼层
powershell第一次启动是有一点慢的
两个桌面的路径不一样,这个不会改呀
idwma 发表于 2023-1-1 18:23



    谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 06:38 , Processed in 0.014824 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表