中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 【求助:关于批处理修改文本】
作者:
标题: 【求助:关于批处理修改文本】 上一主题 | 下一主题
wuhanbin
初级用户





积分 191
发帖 86
注册 2008-8-18
状态 离线
『楼 主』:  【求助:关于批处理修改文本】

我有以文本1.txt,内容如下:
c:\run.dll
c:\windows\x.png
……
想通过批处理把它变成:
“c:\run.dll”-“!:\run.dll”
”c:\windows\x.png“-"!:\windows\x.png"
……
恳求大家帮帮我吧,先谢谢各位了!

2008-8-18 12:35
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
slore
铂金会员





积分 5212
发帖 2478
注册 2007-2-8
状态 离线
『第 2 楼』:  

@echo off
for /f "delims=" %%i in (a.txt) do echo "%%i"-"!:%%~pnxi"
pause



S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
2008-8-18 12:44
查看资料  发短消息 网志   编辑帖子  回复  引用回复
wuhanbin
初级用户





积分 191
发帖 86
注册 2008-8-18
状态 离线
『第 3 楼』:  

谢谢,能告诉我"!:%%~pnxi"是什么意思吗?

2008-8-18 12:56
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 4 楼』:  

看看帮助
for /?

  Quote:
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only

    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string

The modifiers can be combined to get compound results:

    %~dpI       - expands %I to a drive letter and path only
    %~nxI       - expands %I to a file name and extension only
    %~fsI       - expands %I to a full path name with short names only
    %~dp$PATH:I - searches the directories listed in the PATH
                   environment variable for %I and expands to the
                   drive letter and path of the first one found.
    %~ftzaI     - expands %I to a DIR like output line





2008-8-18 13:22
查看资料  发短消息 网志   编辑帖子  回复  引用回复
wuhanbin
初级用户





积分 191
发帖 86
注册 2008-8-18
状态 离线
『第 5 楼』:  

我有以文本1.txt,内容如下:
c:\sys\run.dll
c:\windows\sys\x.png
c:\6.jpg
c:\windows\system\ocx.dll
……
想让批处理自动搜索关键词sys,检测每行文字,如果发现有sys文件夹,则把它变成以sys开头的文本,如果没有检测到sys,就安原样。输出如下:
“c:\sys\run.dll”-"!:\sys\run.dll"
"c:\windows\sys\x.png"-"!:\sys\x.png"
"c:\6.jpg"-"!:\6.jpg"
"c:\windows\system\ocx.dll"-"!:\windows\system\ocx.dll"
(在第一第二行中检测到sys文件夹,在右侧!:后就紧跟sys)
(在第三第四行中未检测到sys文件夹,在右侧:后按原位置保存)

2008-8-18 13:45
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: