Board logo

标题: [系统相关] [已解决]学·知-讨论-多关键词插件路径文件夹查找,以正确判断多版本Photoshop路径 [打印本页]

作者: 34205    时间: 2015-1-26 13:13     标题: [已解决]学·知-讨论-多关键词插件路径文件夹查找,以正确判断多版本Photoshop路径

本帖最后由 34205 于 2015-2-24 11:45 编辑

[已解决]如题,会遇到这样的情况:
1、需要查找软件如Photoshop插件目录Plug-ins,
2、但是我的电脑中有多个PS版本多个Plug-ins目录,
3、需要在结果上添加更多判断,以便找到正确的目录

4、我也是新手,不是秀东西,因为还有个改进的还没有解决,所以想求助。
5、增加关键词是之前没有帖子讨论的,以下代码取自论坛前辈,关于查找文件查找目录的帖子论坛已经发很多

6、需要指点:目前查到程序位置,但是如何将Plug-ins绝对路径 存到一个变量,(也就是如何直接查找目录,而不是文件)
7、其他:也希望大家指出可以改进的地方
【以下代码已经更正,已解决】
  1. @echo off
  2. Mode con: cols=86 lines=36
  3. :StartSet
  4. rem 指定待搜索的关键词条件1
  5. Set "Sting1_FileName=Photoshop.exe"
  6. rem 指定路径中作为参照的关键词条件2
  7. Set "Sting2_PathName=CS6"
  8. :GO
  9. Set This_Path=%cd%
  10. MD TempPSCs6\
  11. cd TempPSCs6\
  12. Set TempPath=%cd%
  13. Set DirFind_Filesname=查找到的路径.txt
  14. Set DirDo_Filesname=满足关键字查找到的路径.txt
  15. Set DirDo_Ineed=目标Plug-ins目录绝对路径.txt
  16. Echo.  >%TempPath%\%DirFind_Filesname%
  17. Cls
  18. echo =============================说明区==============================
  19. Echo.
  20. Echo [Photoshop插件辅助]
  21. Echo 学习-BAT-BAT代码-批处理实现-条件查找Photoshop插件目录
  22. Echo.
  23. Echo 本插件Bat实现以下功能:
  24. Echo 条件查找Photoshop.exe 以正确判断Photoshop\Plug-ins插件目录
  25. Echo.
  26. echo =========================================================S34205==
  27. Echo.
  28. Ping -n 5 127.1>nul
  29. :FindDir
  30. rem 指定待搜索的文件
  31. Echo.
  32. Echo 查找目标:%Sting1_FileName%
  33. Set String1=%Sting1_FileName%
  34. Echo 关键词1 :%String1%
  35. Set string2=%Sting2_PathName%
  36. Echo 关键词2 :%String2%
  37. Echo 批处理目录:%This_Path%
  38. Echo 临时的目录:%TempPath%
  39. Set "ext=*.8bf
  40. Echo.
  41. echo 正在搜索%Sting1_FileName%,请稍候...
  42. Echo.
  43. Echo.
  44. for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  45.     if exist %%a:\nul (
  46.         pushd %%a:\
  47. echo 正在查找文件 %Sting1_FileName%,到达盘符:   %%a
  48.         for /r %%b in ("*%Sting1_FileName%") do (
  49. echo 正在查找文件 %Sting1_FileName%,到达路径:   %%b
  50.             if /i "%%~nxb" equ "%Sting1_FileName%" (
  51.                 set Findpath=%%b &Echo 找到路径: %%b &Echo. &Echo %%b >>%TempPath%\%DirFind_Filesname%
  52.             )
  53.         )
  54.         popd
  55.     )
  56. )
  57. Rem 判断关键词
  58. findstr "%string1%" %DirFind_Filesname% | findstr "%string2%" >%DirDo_Filesname%
  59. Echo.
  60. Echo.
  61. Echo 当前保存的路径文本内容为:
  62. Type %DirDo_Filesname%
  63. echo.
  64. set /p Sting1_DirDo_Filesname=<%DirDo_Filesname%
  65. for %%i in ("%Sting1_DirDo_Filesname%") do (
  66.     set str_Ineed=%%~dpiPlug-ins
  67. Rem 转变文件名路径为文件夹路径
  68. )
  69. Echo %str_Ineed% >%TempPath%\%DirDo_Ineed%
  70. Echo 当前保存的目标Plug-ins目录绝对路径内容为:
  71. echo,%Str_Ineed%
  72. cd %This_Path%
  73. Echo %cd%
  74. Echo.
  75. for /f "delims=" %%i in ('dir /b/s/a-d %ext%') do (Echo 当前目录找到插件文件:%%i  &Set Files8bf=%%i &copy "%%i" "%Str_Ineed%\" >nul 2>nul )
  76. Echo.
  77. if "%Files8bf%" neq "" (Echo OK,%Files8bf% &Echo OK,插件文件已经复制到指定目录 &Echo OK,为你打开Plug-ins插件目录....... &Ping -n 2 127.1>nul &Start "" "%Str_Ineed%\" &Goto Tips) else (Echo. &Echo No,当前目录下没有插件文件,为你打开Plug-ins插件目录....... &Ping -n 2 127.1>nul &Start "" "%Str_Ineed%\" &Goto out)
  78. :Tips
  79. echo Ok,去打开Photoshop查看插件结果吧.........
  80. Echo.
  81. Set "TxtDiy=071122936kfcwggmlxjjdlspp"
  82. mshta vbscript:clipboarddata.setdata("text","%TxtDiy%")(close)
  83. Echo Ok,可能需要用到的注册码(已经复制到剪贴板):%TxtDiy%
  84. Echo.
  85. :Out
  86. Echo.
  87. Echo.
  88. Echo OK,30秒后,退出BAT...................................................................
  89. Ping -n 30 127.1>nul
  90. Del /a /f /s /q %TempPath%\*.*
  91. rd /s /q "TempPSCs6\"
  92. exit /b
复制代码

作者: DAIC    时间: 2015-1-26 13:45

6、需要指点:目前查到程序位置,但是无法使Plug-ins目录存到一个变量,

Rem 判断关键词
findstr "%string1%" %dirfindfilesname% | findstr "%string2%" >%DirDoFilesname%
set /p str=<%DirDoFilesname%
echo,%str%

是这个意思吗?
作者: 34205    时间: 2015-1-26 14:19

本帖最后由 34205 于 2015-1-26 14:20 编辑

回复 2# DAIC


    上面已经达到找到全路径  
.......\CS6\Photoshop.exe

    显然这个结果还不完美,因为我要找到的是
.......\CS6\Photoshop.exe
.......\CS6\Plug-ins(我要输出的是这个)
    并且要把.......\CS6\Plug-ins 输出到文本或者变量,以便下次作为插件的安装目录
    从而实现判断目录路径的目的。
    之前有的前人写的都是查找文件,但是现在我的Plug-ins下没有文件,所以必须找目录的方式。
作者: DAIC    时间: 2015-1-26 14:24

Rem 判断关键词
findstr "%string1%" %dirfindfilesname% | findstr "%string2%" >%DirDoFilesname%
set /p str1=<%DirDoFilesname%
for %%i in ("%str1%") do (
    set str2=%%~dpiPlug-ins
)
echo,%str1%
echo,%str2%

这样可以吗?
作者: 34205    时间: 2015-1-26 14:28

回复 4# DAIC

Ok,完美解决,非常感谢。
目前在路径转换上,个人没有学透,所以卡住了,比如%的环境变量的,需要继续学习。

本帖已经修改更正到1楼。
作者: 34205    时间: 2015-1-26 14:41

本帖最后由 34205 于 2015-1-26 14:42 编辑

回复 4# DAIC


    还能告诉我应该用哪个参数能够实现把我上面例子创建的这个目录   ......\TempPSCs6\ 删除吗?   我用 rd /s /q "%dp0"  不对,因为我已经cd TempPSCs6 ,找不到合适的解决办法。
作者: DAIC    时间: 2015-1-26 15:19

回复 6# 34205
  1. cd /d "%dp0"
  2. rd /s /q "TempPSCs6"
复制代码

作者: 34205    时间: 2015-1-26 16:09

回复 7# DAIC


    谢谢了,好使,学习了。已经更新1楼。[已解决]
作者: 34205    时间: 2015-2-24 11:44

优化程序顺序,2015年2月24日 11:44:24




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2