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

[文件管理] 批处理资源管理器

根据实际编程需要以及batcher的有奖活动特地写个批处理资源管理器,不必计较是不是真的资源管理器,只是模仿。
下面是昨晚尝试的结果:
历史记录功能可用,定位可能需要完善,其他功能有待继续开发。
  1. @echo off&setlocal enabledelayedexpansion
  2. ::Batch Resource Management Program V1.0.1
  3. set "input=%1"
  4. set "rmppath=%~dp0"
  5. set H1=%rmppath%
  6. :rmpMenuPreview 控制台
  7. cls
  8. title %cd%
  9. set rmpvar=
  10. echo;历史记录:!H1!  !H2!  !H3!
  11. echo;=============================================================================
  12. ::echo;打开【O】新建【W】删除【D】重命名【M】属性【R】创建快捷方式【S】关闭【C】
  13. ::echo;编辑【】剪切【】复制【】粘贴【】移动【】
  14. ::echo;查看【】图标【】排列【】刷新【】选择【】搜索【】查看【】收藏【】设置【】
  15. echo;定位【PS】历史记录【H】帮助【Help】
  16. echo;=============================================================================
  17. set num=0
  18. for /f "tokens=*" %%a in ('dir /b') do set /a num+=1&echo;    !num!  %%a&set "rmpvar=%%a"
  19. if "!rmpvar!"=="" echo;    ^<空文件夹^>
  20. echo;
  21. set input=
  22. set inputs=
  23. set /p "input=    请输入:"
  24. if "%input%"=="" goto rmpMenuPreview
  25. if exist "%input%" cd /d "%input%"&call :rmpHistory "%input%"
  26. if /i "%input%"=="Help" call :rmpHelp&goto rmpMenuPreview
  27. if /i "%input:~0,1%"=="H" if "%input:~2,2%"=="" call :rmpHistoryBack&goto rmpMenuPreview
  28. for /f "tokens=1,2" %%a in ("%input%") do if "%%b"=="" (set input=%%a) else (set input=%%a&set inputs=%%b)
  29. echo;
  30. call :rmpLinePosition
  31. echo;
  32. echo;=============================================================================
  33. echo;    ^<The End^>
  34. pause>nul
  35. goto rmpMenuPreview
  36. :rmpLinePosition 处理类型
  37. set num=0
  38. for /f "tokens=*" %%a in ('dir /b') do set /a num+=1&if !num!==!input! (
  39.     echo;    !num!  "%%~a"
  40.     echo;=============================================================================
  41.     if exist "%%~a" (
  42.         if /i %%~xa==.txt  more "%%~a"
  43.         if /i %%~xa==.bat  more "%%~a"
  44.         if /i %%~xa==.cmd  more "%%~a"
  45.         if exist "%%~a" (
  46.             dir /b /a:d "%%~a">nul 2>nul&&((cd /d "%%~a"&call :rmpHistory "%cd%\%%~a"&if not "!inputs!"=="" call :rmpOperationOption "%cd%\%%~na")&goto rmpMenuPreview)||(if not "!inputs!"=="" (call :rmpOperationOption "%cd%\%%~a") else (start "" "%%~a"))
  47.         )
  48.     ) else echo;    "%%~a"
  49. )
  50. goto :eof
  51. :rmpOperationOption 操作设置
  52. echo "%cd%"  "%~1"
  53. if /i "!inputs!"=="PS" Explorer /select,"%~1"
  54. goto :eof
  55. :rmpHelp 帮助信息
  56. cls
  57. echo;=============================================================================
  58. echo;
  59. echo;    基本用法:输入命令或序号执行相应内容
  60. echo;    复合操作【数字+操作】如定位:5 PS
  61. echo;    历史操作【H】如:H2
  62. echo;
  63. echo;=============================================================================
  64. pause>nul
  65. goto :eof
  66. :rmpHistory 历史记录项目设置
  67. for /f %%a in ("%1") do (
  68.     set H9=!H8!
  69.     set H8=!H7!
  70.     set H7=!H6!
  71.     set H6=!H5!
  72.     set H5=!H4!
  73.     set H4=!H3!
  74.     set H3=!H2!
  75.     set H2=!H1!
  76.     set H1=%%~a
  77. )
  78. goto :eof
  79. :rmpHistoryBack 获得历史记录内容
  80. set num=0
  81. if /i "!input!"=="H" (
  82.     echo;&echo;&echo;    历史记录:
  83.     echo;    0  %rmppath%  ^<本程序位置^>
  84. )
  85. for /l %%a in (1,1,9) do (
  86.     set /a num+=1
  87.     if /i "!input!"=="H" echo;    !num!  !H%%a!
  88.     if /i !input!==H%%a cd /d !H%%a!&goto :eof
  89. )
  90. echo;
  91. set num=0
  92. set input=
  93. set /p "input=    请输入:"
  94. if /i "!input!"=="" goto rmpMenuPreview
  95. for /l %%a in (1,1,9) do (
  96.     set /a num+=1
  97.     if /i !input!==0 cd /d %rmppath%&goto :eof
  98.     if /i !input!==%%a cd /d !H%%a!&goto :eof
  99. )
  100. goto rmpMenuPreview
  101. tree /f
  102. pause
复制代码
寂寞是黑白的,但黑白不是寂寞,是永恒。BAT 需要的不是可能,而是智慧。

很不错了哦

TOP

它不能打开LNK

TOP

本人为学生,之前常来本论看贴,但未能注册。
以下代码为本人原创:
  1. @echo off
  2. :main
  3. setlocal enabledelayedexpansion
  4. :: 初始化配置
  5. set "config_choice_options=:abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  6. set "config_dir_order=/o:n"
  7. set "config_dir_other=/a /b"
  8. set "config_lines_per_page=10"
  9. set "config_choice_setting_1=/c%config_choice_options% /cs /n"
  10. set "config_last_page=1"
  11. set "config_next_page=4"
  12. set "config_to_page=5"
  13. set "config_back=17"
  14. set "config_file_open=15"
  15. set "config_file_exit=17"
  16. set "main_message=[!config_choice_options:~%config_last_page%,1!] 上一页   [!config_choice_options:~%config_next_page%,1!] 下一页   [!config_choice_options:~%config_to_page%,1!] 跳转到指定页   [!config_choice_options:~%config_back%,1!] 返回上级目录"
  17. set "file_options=[!config_choice_options:~%config_file_open%,1!] 打开文件   [!config_choice_options:~%config_file_exit%,1!] 返回"
  18. rem [!config_choice_options:~%%,1!]
  19. :: 加载当前目录内容
  20. :load_current_directory
  21. set "current_dir=%cd%"
  22. set /a current_page=1
  23. set /a total_pages=1
  24. set /a total_lines=0
  25. for /f "tokens=*" %%a in ('dir "%current_dir%" %config_dir_order% %config_dir_other% /-c') do (
  26.     set /a total_lines+=1
  27.     set "files[!total_lines!]=%%a"
  28. )
  29. :: 计算总页数
  30. set /a total_pages=(total_lines+config_lines_per_page-1)/config_lines_per_page
  31. goto detect_user_action
  32. REM goto show_current_page_1
  33. REM goto :eof
  34. :: 显示当前页
  35. :show_current_page_1
  36. set file_index=0
  37. :show_selected_1
  38. set /a start_line=(current_page-1)*config_lines_per_page+1
  39. set /a end_line=start_line+config_lines_per_page-1
  40. if %end_line% gtr %total_lines% set /a end_line=%total_lines%
  41. set "selectedmark="
  42. for /l %%i in (%start_line%,1,%end_line%) do (
  43.     set "file_line=!files[%%i]!"
  44. set /a current_line = %%i - %start_line% + 1
  45. if %file_index% equ %%i (
  46. set "selectedmark=---"
  47. ) else (
  48. set "selectedmark=   "
  49. )
  50. if exist "%current_dir%\!file_line!\*" (
  51.         set "this_line[!current_line!]=^|%%i^|!selectedmark!目录 - !file_line!"
  52.     ) else (
  53.         set "this_line[!current_line!]=^|%%i^|!selectedmark!文件 - !file_line!"
  54.     )
  55. )
  56. cls
  57. echo 当前目录:%current_dir%
  58. echo 当前页:%current_page% / %total_pages%
  59. for /l %%i in (1,1,%current_line%) do (
  60. echo !this_line[%%i]!
  61. )
  62. echo.
  63. REM goto detect_user_action
  64. goto :eof
  65. :show_current_page_2
  66. REM 本部分代码未完善,但以下循环理论上可以正常显示。
  67. for /f "tokens=* delims=" %%a in ('dir /b /a %config_dir_setting% ^| more +%start_line%') do (
  68.     set /a counter+=1
  69.     echo !counter!. %%a
  70. REM  skip=%start_line%
  71.     rem 这里根据文件或文件夹的类型进行标记
  72.     rem 可以使用 if exist "%%a\" (echo [DIR]) else (echo [FILE])
  73.     if !counter! equ %config_lines_per_page% goto next
  74. )
  75. goto :eof
  76. :: 捕捉用户行为
  77. :detect_user_action
  78. call :show_current_page_1
  79. echo 请选择操作:
  80. echo [1-10(0代表10)] 选择文件/目录
  81. echo %main_message%
  82. choice %config_choice_setting_1% /m "请按一下对应按键:"
  83. :: 处理用户输入
  84. set /a error_level=%ERRORLEVEL%
  85. :: 翻页操作
  86. if %error_level% equ %config_last_page% (
  87.     if %current_page% gtr 1 (
  88.         set /a current_page-=1
  89.     )
  90.     goto detect_user_action
  91. )
  92. if %error_level% equ %config_next_page% (
  93.     if %current_page% lss %total_pages% (
  94.         set /a current_page+=1
  95.     )
  96.     goto detect_user_action
  97. )
  98. if %error_level% equ %config_to_page% (
  99.    set /p "to_page=请输入要到达的页数:"
  100.     if !to_page! lss 1 (
  101. set to_page = 1
  102. )
  103. if !to_page! gtr %total_pages% (
  104. set to_page = %total_pages%
  105. )
  106. set /a current_page = to_page
  107. goto detect_user_action
  108. )
  109. :: 返回上级目录
  110. if %error_level% equ %config_back% (
  111.     cd..
  112.     goto load_current_directory
  113. )
  114. if %error_level% geq 27 (
  115.     set /a file_index = %config_lines_per_page% * %current_page% - %config_lines_per_page% + %error_level% - 26
  116.     REM if %file_index% lss %start_line% goto invalid_choice
  117.     REM if %file_index% gtr %end_line% goto invalid_choice
  118.     goto select_file_or_directory
  119. )
  120. REM :: 无效选择
  121. REM :invalid_choice
  122. echo 无效的选择,请重试...
  123. timeout /t 2 >nul
  124. goto detect_user_action
  125. :: 处理文件或文件夹选择
  126. :select_file_or_directory
  127. set "file_name=!files[%file_index%]!"
  128. if exist "%current_dir%\%file_name%\*" (
  129.     cd "%current_dir%\%file_name%"
  130.     goto load_current_directory
  131. ) else (
  132.     goto file_options
  133. )
  134. goto select_file_or_directory
  135. :: 文件操作菜单
  136. :file_options
  137. cls
  138. call :show_selected_1
  139. echo 已选择文件:[%file_index%] %file_name%
  140. echo %file_options%
  141. choice %config_choice_setting_1% /m "输入操作:"
  142. set /a error_level=%ERRORLEVEL%
  143. if %error_level% equ %config_file_open% (
  144.     start "" "%file_name%"
  145.     goto detect_user_action
  146. )
  147. if %error_level% equ %config_file_exit% (
  148.     goto detect_user_action
  149. )
  150. goto file_options
复制代码

TOP

返回列表