尝试在for循环中调用另一个批处理文件,得到“系统找不到指定的路径”错误

时间:2018-05-30 15:34:08

标签: batch-file

我一直试图在下面调试我的代码几个小时,但仍然无法弄清楚下面的代码有什么问题。我收到“系统找不到指定的路径”错误。对此提出一些建议。谢谢。

 @echo off &setlocal
    setlocal enableextensions enabledelayedexpansion
    for /f "delims=" %%i in ('dir /b "D:\*.bat"') do (
        for /f "usebackq tokens=1-4 delims=," %%a in ("sample.csv") do (
            set "search=profile"
            set "replace=profile-%%a"
            set "textfile=login.txt"
            set "newfile=login-%%a.txt"
            call Repl.bat "%search%" "%replace%" L < "%textfile%" > "%newfile%"     
            echo %%a %%b !search! !replace!
            )
    )

1 个答案:

答案 0 :(得分:0)

您已经在批处理文件调用下方的行中使用了所需的延迟扩展:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlProperty>

#include <QDebug>

class Backend: public QObject{
    Q_OBJECT
    Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
public:
    QString text() const{
        return mText;
    }
   void setText(const QString &text){
        if(text == mText)
            return;
        mText = text;
        emit textChanged(mText);
    }
signals:
    void textChanged(const QString & text);
private:
    QString mText;
};

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    Backend backend;

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("backend", &backend);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    // test

    QObject::connect(&backend, &Backend::textChanged, [](const QString & text){
        qDebug() << text;
    });
    return app.exec();
}

#include "main.moc"

但是,由于您已经在使用import QtQuick 2.9 import QtQuick.Window 2.2 import QtQuick.Controls 2.4 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") TextField { id: serverField1 x: 15 y: 46 width: 120 height: 45 topPadding: 8 font.pointSize: 14 bottomPadding: 16 placeholderText: "Server Ip" renderType: Text.QtRendering onTextChanged: backend.text = text } } ,因此您可以将字符百分比加倍:

@Echo Off
SetLocal EnableDelayedExpansion
For /F "UseBackQ Tokens=1-2 Delims=," %%A In ("sample.csv") Do (Set "search=profile"
    Set "replace=profile-%%A"
    Set "textfile=login.txt"
    Set "newfile=login-%%A.txt"
    Call "Repl.bat" "!search!" "!replace!" L<"!textfile!">"!newfile!"
    Echo %%A %%B !search! !replace!)
Pause

您当然可以决定不必要地设置变量,从而消除对延迟扩展的依赖:

Call

或者预先设置它们,以便您可以更轻松地管理它们,而不是将它们设置在循环中并消除延迟的扩展依赖性:

@Echo Off
SetLocal EnableDelayedExpansion
For /F "UseBackQ Tokens=1-2 Delims=," %%A In ("sample.csv") Do (Set "search=profile"
    Set "replace=profile-%%A"
    Set "textfile=login.txt"
    Set "newfile=login-%%A.txt"
    Call "Repl.bat" "%%search%%" "%%replace%%" L<"%%textfile%%">"%%newfile%%"
    Echo %%A %%B !search! !replace!)
Pause