Batch file 批处理脚本,将文件名复制到txt文件
任何人都可以帮助,我板条箱一个批处理脚本,将创建一堆txt文件从我的列表,txt然后需要包含几行文字和它的一部分将需要有一个文件的名称。 所以,例如 那么.txt文件需要有:Batch file 批处理脚本,将文件名复制到txt文件,batch-file,Batch File,任何人都可以帮助,我板条箱一个批处理脚本,将创建一堆txt文件从我的列表,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:使用编辑链接编辑您的问题(当然是明智的)) 到目
this file contains info
owner of the file is 'file.txt'
data for this file is in C:\Users\'file.txt'
如果这不够清楚,请告诉我
谢谢
(复制/格式化OP的评论-OP:使用编辑链接编辑您的问题(当然是明智的)) 到目前为止我已经写过了
@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文件。然后我试着跑步
复制>>email@domain.com
对于列表中的每个电子邮件地址,然后
复制con>>每个文件的名称
刚才添加的语法对txt文件是正确的。抱歉,伙计们,我对批处理脚本非常陌生。如果您想在文件中写入内容,则需要在批处理文件中写入:
@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
我希望这对你有帮助
附言:对不起,我的英语不好 你打算做什么还不清楚 您的代码似乎想做的是将“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
notTYPE
和>“%%a”
,因为元变量%%a
将包含文件名*.txt
,“引号”确保文件名包含空格.txt
处理正确。@user2782162您需要编辑您的问题并更加具体。
我已经创建了下面的批基于什么'我认为'你正试图做
如果这是你想要的,请告诉我们?
另外……我相信@Magoo可以让这件事简单得多(你是个能手)
这是假设您的输入文件“list.txt”如下所示…每个“新文件”的所有信息都在单独的行中,如下所示
list.txt的内容
批处理将一次读取“list.txt”1行。
它将使用每行上“customer”的值作为新文件的名称
下面的示例显示第一行的输出将是什么样子
hello1.txt的内容
你需要展示你已经尝试过的东西,如果你还没有尝试过,不要指望其他人会付出努力。所以请给出一个完整的例子来详细说明。到目前为止,我已经在(.txt)中为%%a写了@echo offdo type customer=customer fromAddress=email@domain.comandOrAddress=或toAddress=email@domain.comoutputPath=E:\Exgest\customer\email@domain.comoutputFormat=MIME customHeaders=true fromDate=20030901 toDate=20101231>>(.txt)无法添加文本,仅在该文件夹中创建了*.txt文件,然后我尝试运行copy>>email@domain.com对于列表中的每个电子邮件地址,然后将刚刚添加语法正确的每个文件的名称复制到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"
@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
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
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