DOS批处理器移动指定数量文件到一个临时文件夹,上传到linux服务器,并删除临时文件夹下的文件,上传需要依赖pscp.exe。
脚本如下:
1
2
3
4
5
6
7
8
9
|
@echo off&setlocal enabledelayedexpansion
#将400个xml文件从M:\dockerEPG\目录下移动到M:\scpepg\tmp\目录下
for /f "delims=" %%i in ('dir/a-d/b/s "M:\dockerEPG\*.xml"') do (set /a n+=1
if !n! leq 400 (move "%%i" "M:\scpepg\tmp\"))
#pscp 带密码上传文件到172.28.8.81linux服务器的/mnt/EPG/目录下
M:\scpepg\pscp.exe -pw itvitv M:\scpepg\tmp\*.xml root@172.28.8.81:/mnt/EPG/
#删除临时文件夹下的xml文件
del M:\scpepg\tmp\*.xml /f /s /q /a
pause
|
将一个文件夹文件移动到另一个文件夹,指定数量和后缀
1.
1
2
3
4
|
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir/a-d/b/s "D:\a\*.rar"') do (set /a n+=1
if !n! leq 100 (move "%%i" "D:\b\"))
pause
|
2.
1
2
3
4
|
@echo off&setlocal enabledelayedexpansion
for /r "D:\a" %%i in (*.rar) do (set /a n+=1
if !n! leq 100 (move "%%i" "D:\b\"))
pause
|
循环上传
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
@echo off&setlocal enabledelayedexpansion
set sleep=ping 127.0.0.1 -n
set /a m=1
:loop
echo 第%m%次循环开始...... %date% %time%
set /a n=1
for /f "delims=" %%i in ('dir/a-d/b/s "M:\dockerEPG\*.xml"') do (set /a n+=1
if !n! leq 500 (move "%%i" "M:\scpepg\tmp\"))
M:\scpepg\pscp.exe -pw itvitv M:\scpepg\tmp\*.xml root@172.28.8.81:/mnt/EPG/
del M:\scpepg\tmp\*.xml /f /s /q /a
echo 第%m%次循环结束...... %date% %time%
echo 休息180秒吧.....
%sleep% 180 > nul
set /a m+=1
if "%n%" leq 16 goto loop
pause
|
本文转自 326647452 51CTO博客,原文链接:http://blog.51cto.com/svsky/1929278,如需转载请自行联系原作者