中国DOS联盟

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

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

中国DOS联盟论坛
现在时间是 2026-06-21 10:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [解决]批处理读取一个txt文件的文件路径,执行copy操作? 查看 964 回复 5
楼 主 [解决]批处理读取一个txt文件的文件路径,执行copy操作? 发表于 2010-10-21 11:47 ·  中国 广东 深圳 电信
初级用户
积分 29
发帖 29
注册 2008-11-18 16:19
17年会员
UID 131353
性别 男
状态 离线
有个文本filelist.txt,里面是一些文件和文件夹路径,如下:
\prcweb\website\Templates\zh_CN\index.htm
\prcweb\website\Templates\zh_TW\index.htm
\prcweb\website\Common\Pub_Function.asp
\prcweb\website\Templates\zh_CN\about\news
\prcweb\website\Templates\zh_TW\about\news
\prcweb\website\newFolder

想写个批处理,把批处理和filelist.txt放到跟prcweb平行的目录,执行批处理后,读取filelist,copy里面指定的文件和文件夹到新的路径d:\test\下,

比如执行批处理后,d:\test下的内容是:
d:\test\prcweb\website\Templates\zh_CN\index.htm
d:test\prcweb\website\Templates\zh_TW\index.htm
d:\test\prcweb\website\Common\Pub_Function.asp
d:\test\prcweb\website\Templates\zh_CN\about\news
d:\test\prcweb\website\Templates\zh_TW\about\news
d:\test\prcweb\website\newFolder

请高人指点.3ks!

[ Last edited by boy on 2010-10-22 at 19:07 ]
2 发表于 2010-10-21 12:29 ·  中国 北京 263网络通信电信数据中心
铂金会员
★★★★
积分 5,212
发帖 2,478
注册 2007-02-08 23:39
19年会员
UID 79003
性别 男
状态 离线
@echo off
for /f "delims=" %%i in (filelist.txt) do echo %cd%%%i
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
3 不行啊 发表于 2010-10-21 12:47 ·  中国 广东 深圳 电信
初级用户
积分 29
发帖 29
注册 2008-11-18 16:19
17年会员
UID 131353
性别 男
状态 离线
Originally posted by slore at 2010-10-21 12:29:
@echo off
for /f "delims=" %%i in (filelist.txt) do echo %cd%%%i

我这样写的
@echo off
for /f "delims=" %%i in (filelist.txt) do start /b xcopy /s/h/r/y/c %cd%%%i "d:\cms\"
但是执行完后,d:\cms\下没有像filelist.txt里那样的目录啊,都是单个的文件...
需要怎样改一下啊?谢了

[ Last edited by boy on 2010-10-21 at 15:06 ]
4 发表于 2010-10-21 16:26 ·  中国 广东 深圳 电信
初级用户
积分 29
发帖 29
注册 2008-11-18 16:19
17年会员
UID 131353
性别 男
状态 离线
复制后,怎样保持原目录结构不变呢?
我想执行批处理后,d:\test下的内容是:
d:\test\prcweb\website\Templates\zh_CN\index.htm
d:test\prcweb\website\Templates\zh_TW\index.htm
d:\test\prcweb\website\Common\Pub_Function.asp
d:\test\prcweb\website\Templates\zh_CN\about\news
d:\test\prcweb\website\Templates\zh_TW\about\news
d:\test\prcweb\website\newFolder
5 发表于 2010-10-22 07:17 ·  中国 台湾 台湾宽频通讯顾问股份有限公司
初级用户
★★
积分 68
发帖 64
注册 2009-05-23 20:43
17年会员
UID 145803
性别 男
状态 离线
(1) the problem is your filelist.txt that is not absolute path
(2) try below batch after change to absolute path ( for example, D:\myfolder\prcweb\website\Templates\zh_CN\index.htm )

D:\myfolder\prcweb\website\Templates\zh_CN\index.htm
D:\myfolder\prcweb\website\Templates\zh_TW\index.htm
D:\myfolder\prcweb\website\Common\Pub_Function.asp
D:\myfolder\prcweb\website\Templates\zh_CN\about\news
D:\myfolder\prcweb\website\Templates\zh_TW\about\news
D:\myfolder\prcweb\website\newFolder


@echo off
for /f "delims=" %%i in (filelist.txt) do start /b xcopy /s/h/r/y/c/e %%i "d:\cms\"
6 发表于 2010-10-22 09:54 ·  中国 广东 深圳 电信
初级用户
积分 29
发帖 29
注册 2008-11-18 16:19
17年会员
UID 131353
性别 男
状态 离线
Originally posted by pdanniel66 at 2010-10-22 07:17:
(1) the problem is your filelist.txt that is not absolute path
(2) try below batch after change to absolute path ( for example, D:\myfolder\prcweb\website\Templates\zh_CN\index.htm )

D:\myfolde ...

还是不行,跟我之前的代码一样的效果,这个和filellst.txt中的路径是否为绝对路径无关,因为执行xcopy的时候,%cd%%%i已经将路径转为了绝对路径.
论坛跳转: