0

谁能帮忙,我创建了一个批处理脚本,它将从我拥有的列表中创建一堆 txt 文件,然后 txt 需要在文本上包含几行,其中的一部分需要具有文件名。所以例如。

 mkdir file1.txt

那么 .txt 文件需要有:

 this file contains info
 owner of the file is 'file.txt'
 data for this file is in C:\Users\'file.txt'

如果这还不够清楚,请告诉我谢谢


(从 OP 的评论中复制/格式化 - OP:使用 EDIT 链接编辑您的问题(当然是明智的))

到目前为止我已经写了

@echo off 
for %%a in (*.txt) do type customer=customer fromAddress=email@domain.com andOrAddress=OR toAddress=email@domain.com outputPath=E:\Exgest\customer\email@domain.com outputFormat=MIME customHeaders=true fromDate=20030901 toDate=20101231 >> (*.txt)

这未能添加文本,仅在此文件夹中创建了 *.txt 文件。然后我尝试运行 copy >> email@domain.com

对于列表中的每个电子邮件地址,然后复制 con >> 每个文件的名称

刚刚添加的语法对txt文件是正确的。对不起,伙计们,我对批处理脚本很陌生。

4

3 回答 3

0

如果你想在一个文件中写一些东西,那么你需要把它写在一个批处理文件中:

@ECHO OFF

ECHO.this file contains info>>file.txt
ECHO.owner of the file is 'file.txt'>>file.txt
ECHO.data for this file is in C:\Users\'file.txt'>>file.txt

ECHO.编写您想要发送到具有任何扩展名的文件之前。在您想在该文件中写入什么之前,>如果您只想保留一行写入,并且>>如果您想在该文件中写入更多行,请写入。

因此,如果您有:

ECHO.thing>>file.txt
ECHO.thing2>file.txt

file.txt将如下所示:

thing2

我希望这对你有帮助。

PS:对不起我的英语不好!

于 2013-11-21T19:21:36.753 回答
0

@user2782162 您需要编辑您的问题并更具体。我根据您正在尝试做的“我认为”创建了以下批次。

请让我们知道这是否是您想要的?另外......我确信@Magoo 可以让这变得更简单(你是一个奇才)。

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET listloc=list.txt

:start
FOR /f "tokens=* delims= " %%a IN (%listloc%) DO CALL :process1 %%a
ECHO.
ECHO List finished - Press any key to close.
PAUSE >nul
GOTO :eof


:process1
SET fname=%2
IF "%2"=="" GOTO :eof
:process2
ECHO %1=%2 >>%fname%.txt
SHIFT
SHIFT
IF NOT "%2"=="" GOTO process2
GOTO :eof

这是假设您的输入文件“list.txt”的排列方式如下......每个“新文件”的所有信息都在这样的单独行上......

list.txt 的内容

 customer=hello1 fromAddress=email1@domain.com andOrAddress=OR1 toAddress=email1@domain.com outputPath=E:\Exgest\customer\email@domain1.com outputFormat=MIME1 customHeaders=true1 fromDate=200309011 toDate=201012311
 customer=hello2 fromAddress=email2@domain.com andOrAddress=OR2 toAddress=email2@domain.com outputPath=E:\Exgest\customer\email@domain2.com outputFormat=MIME2 customHeaders=true2 fromDate=200309012 toDate=201012312
 customer=hello3 fromAddress=email3@domain.com andOrAddress=OR3 toAddress=email3@domain.com outputPath=E:\Exgest\customer\email@domain3.com outputFormat=MIME3 customHeaders=true3 fromDate=200309013 toDate=201012313

批处理将一次读取 'list.txt' 1 行。它将使用每一行上“客户”的值作为新文件的名称。

下面的示例显示了第一行的输出将是什么样子..

hello1.txt 的内容

 customer=hello1 
 fromAddress=email1@domain.com 
 andOrAddress=OR1 
 toAddress=email1@domain.com 
 outputPath=E:\Exgest\customer\email@domain1.com 
 outputFormat=MIME1 
 customHeaders=true1 
 fromDate=200309011 
 toDate=201012311 
于 2013-11-22T12:37:27.580 回答
0

你打算做什么还不清楚。

您的代码似乎想要做的是将“customer=customer fr...01 toDate=20101231”附加到每个现有的 .TXT 文件中。正确的语法是

@echo off 
for %%a in (*.txt) do ECHO customer=customer fromAddress=email@domain.com andOrAddress=OR toAddress=email@domain.com outputPath=E:\Exgest\customer\email@domain.com outputFormat=MIME customHeaders=true fromDate=20030901 toDate=20101231 >>"%%a"

.txt这应该在每个文件的末尾添加额外的行。

请注意更改 -ECHO不是因为元变量将包含文件的文件名-TYPE并且 “引号”确保正确处理。>>"%%a"%%a*.txt"filenames containing spaces.txt"

于 2013-11-21T19:47:28.790 回答