标题: [文件操作] [已解决]BAT如何批量复制文件到指定目录下面? [打印本页]
作者: xxlaila 时间: 2015-7-4 15:32 标题: [已解决]BAT如何批量复制文件到指定目录下面?
本帖最后由 xxlaila 于 2015-7-21 13:53 编辑
我D:\盘有a.test.com.rar,b.test.com.rar,c.test.com.rar,d.test.com.rar。我用- @echo off
- echo.
- echo.=====================================================================
- Setlocal Enabledelayedexpansion
- set FolderName=D:\FTP
- for /f "delims=" %%a in ('dir /b /a-d /oN "%FolderName%\*.*"') do (
- set d=%%a
- set c=!d:~0,-4!
- echo !c!
- )
- echo.
复制代码
文件显示出来了,
怎么把a.test.com.rar复制到D:\WEB\a.test.com\RAR
怎么把b.test.com.rar复制到D:\WEB\b.test.com\RAR
作者: DAIC 时间: 2015-7-4 17:49
@echo off
Setlocal Enabledelayedexpansion
set FolderName=D:\FTP
for /f "delims=" %%a in ('dir /b /a-d /oN "%FolderName%\*.*"') do (
set d=%%a
set c=!d:~0,-4!
echo !c!
copy /y "%FolderName%\!c!" "D:\WEB\!c!\RAR\"
)
作者: xxlaila 时间: 2015-7-4 17:57
回复 2# DAIC
不能进行复制,目录下面是多个文件,不是一个
作者: xxlaila 时间: 2015-7-4 18:00
回复 DAIC
不能进行复制,目录下面是多个文件,不是一个
xxlaila 发表于 2015-7-4 17:57
可以了! 我输出了日志,看到了,不好意思,少添加一个.rar
谢谢啊
作者: xxlaila 时间: 2015-7-6 09:20
@echo off
echo.
echo.=====================================================================
Setlocal Enabledelayedexpansion
set FolderName=D:\FTP
set PathName=d:\WwwRoot
for /f "delims=" %%a in ('dir /b /a-d /oN "%FolderName%\*.*"') do (
set d=%%a
set c=!d:~0,-4!
echo !c!
xcopy /y "%FolderName%\!c!.rar" "D:\WwwRoot\!c!\News\"
)
怎么能实现 复制的a.tet.com.rar 就启动a.bat 如果是b.test.com.rar 就启动b.bat 两个都复制了 a.bat和b.bat 都启动
作者: Batcher 时间: 2015-7-6 09:21
- @echo off
- echo.
- echo.=====================================================================
- Setlocal Enabledelayedexpansion
- set FolderName=D:\FTP
- set PathName=d:\WwwRoot
- for /f "delims=" %%a in ('dir /b /a-d /oN "%FolderName%\*.*"') do (
- set d=%%a
- set c=!d:~0,-4!
- echo !c!
- xcopy /y "%FolderName%\!c!.rar" "D:\WwwRoot\!c!\News\"
- if "!c!" equ "a.test.com" (
- start "" "a.bat"
- ) else if "!c!" equ "b.test.com" (
- start "" "b.bat"
- )
- )
复制代码
作者: Batcher 时间: 2015-7-6 09:47
- @echo off
- echo.
- echo.=====================================================================
- Setlocal Enabledelayedexpansion
- set FolderName=D:\FTP
- set PathName=d:\WwwRoot
- for /f "delims=" %%a in ('dir /b /a-d /oN "%FolderName%\*.*"') do (
- set d=%%a
- set c=!d:~0,-4!
- echo !c!
- xcopy /y "%FolderName%\!c!.rar" "D:\WwwRoot\!c!\News\"
- if "!c!" equ "a.test.com" (
- start "" "a.bat"
- )
- if "!c!" equ "b.test.com" (
- start "" "b.bat"
- )
- )
复制代码
作者: xxlaila 时间: 2015-7-6 09:48
本帖最后由 xxlaila 于 2015-7-6 09:49 编辑
这个没能实现 复制的a.tet.com.rar 就启动a.bat 如果是b.test.com.rar 就启动b.bat
如果a.tet.com.rar ,b.tet.com.rar ,c.tet.com.rar , 三个都复制了 a.bat和b.bat 、c.bat都启动,上面的那样写法只启动了b.bat 。其他都没有启动
作者: Batcher 时间: 2015-7-6 10:42
回复 8# xxlaila - @echo off
- echo.
- echo.=====================================================================
- Setlocal Enabledelayedexpansion
- set FolderName=D:\FTP
- set PathName=d:\WwwRoot
- for /f "delims=" %%a in ('dir /b /a-d /oN "%FolderName%\*.*"') do (
- set d=%%a
- set c=!d:~0,-4!
- echo !c!
- xcopy /y "%FolderName%\!c!.rar" "D:\WwwRoot\!c!\News\"
- if "!c!" equ "a.test.com" (
- start "" "a.bat"
- )
- if "!c!" equ "b.test.com" (
- start "" "b.bat"
- )
- if "!c!" equ "c.test.com" (
- start "" "c.bat"
- )
- )
复制代码
作者: xxlaila 时间: 2015-7-6 11:56
恩,可以了,谢谢,我在去生产环境测试测试 。3QY
作者: xxlaila 时间: 2015-7-6 15:22
@echo off
echo.
echo.=====================================================================
Setlocal Enabledelayedexpansion
set FolderName=D:\FTP
set PathName=d:\WwwRoot
for /f "delims=" %%a in ('dir /b /a-d /oN "%FolderName%\*.*"') do (
set d=%%a
set c=!d:~0,-4!
echo !c!
xcopy /y "%FolderName%\!c!.rar" "D:\WwwRoot\!c!\News\"
if "!c!" equ "a.test.com" (
start "" "a.bat" >d:\log\a.log
)
if "!c!" equ "b.test.com" (
start "" "b.bat" >d:\log\b.log
)
if "!c!" equ "c.test.com" (
start "" "c.bat" >d:\log\c.log
)
)
这样子不能记录脚本没执行的日志,请问怎么解决这个问题
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |