2010-09-17 115 views
0

,如果我有一个具有以下一个.txt:批处理文件添加字符

2005050“2005年2月19日”
2005060“2005年3月1日”
2005070“2005年3月11日“
2005080‘2005年3月21日’
2005090‘2005年3月31日’

有批处理文件的方式来阅读,总是在7

字符的末尾添加巴纽

例如。

2005050.png “2005年2月19日”
2005060.png “2005年3月1日”
2005070.png “2005年3月11日”
2005080.png “2005年3月21日”
2005090.png“2005年3月31日”

+0

你想让批处理文件更新文本文件,还是创建一个新的文本文件? – LittleBobbyTables 2010-09-17 00:22:36

+0

在新的txt文件中 – steven 2010-09-17 00:25:33

回答

3

该批处理文件将在第一个空格处拆分每行,并在拆分之前将.png附加到字符串。该脚本读取来自infile.txt的行并输出到outfile.txt。

@echo off 
echo. > outfile.txt 
for /f "tokens=1*" %%i in (infile.txt) do echo %%i.png %%j >> outfile.txt 

更新

或者删除outfile.txt第一....

@echo off 
del /q /f outfile.txt 
for /f "tokens=1*" %%i in (infile.txt) do echo %%i.png %%j >> outfile.txt 

另一个更新

只需添加新记录outfile.txt做一些像......

@echo off 
for /f "tokens=1*" %%i in (infile.txt) do (
    find "%%i.png %%j" outfile.txt > nul 
    if errorlevel 1 then (
     echo %%i.png %%j >> outfile.txt 
    ) 
) 
+0

echo。 > outfile.txt不是必需的。它会在outfile.txt中创建第一个空行 – DmitryK 2010-09-17 00:32:35

+0

我把它放进去以确保outfile.txt在for循环开始附加到它之前是空白的。我可以使用del来确保它不在那里。 – 2010-09-17 00:35:54

+0

这就是我离开电脑几分钟所得到的:)好的回答 – LittleBobbyTables 2010-09-17 00:37:32

0

我的答案失败:我没有尝试,但我不能让SET内的工作

@echo off 

set str1=ooo 
set str2=ppp 

for /f "tokens=*" %%a in ('type testprog.txt') do (

    set str=!%%a! 
    echo %%str:~0,7%%.png %%str:~-5,14%% >> tempprog.txt 

) 

move tempprog.txt testprog.txt 
start testprog.txt 

也许有人可以编辑工作版本,因为我想看什么 我做错了...