Board logo

标题: [解决]批处理读取一个txt文件的文件路径,执行copy操作? [打印本页]

作者: boy     时间: 2010-10-21 11:47    标题: [解决]批处理读取一个txt文件的文件路径,执行copy操作?

有个文本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 ]
作者: slore     时间: 2010-10-21 12:29
@echo off
for /f "delims=" %%i in (filelist.txt) do echo %cd%%%i
作者: boy     时间: 2010-10-21 12:47    标题: 不行啊



  Quote:
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 ]
作者: boy     时间: 2010-10-21 16:26
复制后,怎样保持原目录结构不变呢?
我想执行批处理后,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
作者: pdanniel66     时间: 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:\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\"
作者: boy     时间: 2010-10-22 09:54


  Quote:
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已经将路径转为了绝对路径.