【问题标题】:Drag and drop files and folders into command batch将文件和文件夹拖放到命令批处理中
【发布时间】:2019-03-04 15:09:31
【问题描述】:

这是我在你的帮助下完成的最后一个代码。

@echo off
Title ..::RoboCoveriZer: Auto add covers to your MKV::..
Mode con cols=81 lines=9
IF "%~1"=="" Goto:Error
set mkvpredt=mkvpropedit.exe
pushd "%~1"
for %%I in ("*.mkv") DO (
"%mkvpredt%" "%%~nxI" --attachment-name "cover" --attachment-mime-type "image/jpeg" --add-attachment "%%~nI.jpg"
)
pause
exit

有什么方法可以打开命令窗口并让它等待拖放以启动进程?

【问题讨论】:

  • 不要使用[]Use quotes instead
  • @Stephan 是正确的。替换:IF [%1] EQU [] Goto:Error 为:IF "%1"=="" Goto :Error
  • 你有IF "%1"pushd "%~1"。处理第一个参数的不一致使得"%1""%~1" 可能失败。如果引用了参数并且您添加了引号,则引号配对可能会更改。我会使用"%~1",因为它会去除引号并添加引号,因此与原始参数的引用相同。
  • @michael_heath 你的意思是这样吗? IF "%~1" ?

标签: batch-file


【解决方案1】:
@echo off
setlocal
title ..::RoboCoveriZer: Auto add covers to your MKV::..
mode con cols=81 lines=9

set "mkvpredt=mkvpropedit.exe"

:: Get all arguments.
set input=%*

:: Get input path(s) if needed.
if not defined input set /p "input=Enter MKV path(s): "

:: Exit if no input.
if not defined input exit /b

:: Display each argument (optional code).
if defined input for %%A in (%input%) do echo input: %%A

:: Call each argument which can be a file or folder.
for %%A in (%input%) do call :step_1 "%%~A"

pause
exit /b


:step_1
:: Process a folder of MKV files or a single file.

:: Call each MKV file if pushd succeeds.
2>nul pushd "%~1" && (
    for %%A in (*.mkv) do call :step_2 "%%~A"
    popd
    exit /b
)

:: Exit if not MKV file.
if /i not "%~x1" == ".mkv" exit /b 1

:: Call single MKV file.
call :step_2 "%~1"
exit /b


:step_2
:: Coverize MKV file.
echo "%mkvpredt%" "%~f1"^
 --attachment-name "cover"^
 --attachment-mime-type "image/jpeg"^
 --add-attachment "%~dpn1.jpg"
exit /b

文件上的拖放操作由%* 处理。 命令行参数由%* 处理。 如果将%* 分配给名为input 的变量 如果未定义input,则使用set /p 从用户那里获取输入。用户可以 拖放或键入文件或文件夹到 满足set /p 的窗口并按下 返回继续。

提供的代码可以处理这些动作 提到并且可以处理文件和文件夹 路径。

第一个 for 循环传递每个参数 到call :step_1。这可以是一个文件或 可以包含通配符的文件夹路径 模式。

标签:step_1 在参数上尝试pushd 通过,如果成功,则循环通过 *.mkv 并调用标签:step_2 每个文件作为参数。如果 pushd 失败,处理 它作为一个文件和call :step_2 与 文件作为参数。

:step_2 会覆盖echo 被删除。

【讨论】:

    猜你喜欢
    • 2012-01-27
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多