Windows批处理文件将X个文件从一个文件夹移动到另一个文件夹 [英] Windows Batch file to move X number of files from folder to folder

查看:386
本文介绍了Windows批处理文件将X个文件从一个文件夹移动到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果%DataLoc%中的文件少于20个,我正在尝试使用批处理文件以30个为一组移动文件.我从

I'm trying to use a batch file to move files in blocks of 30 if there are less than 20 files in %DataLoc%. I modified code from a prior question. The problem is in the FMove section of the file. No matter what I put in the for line, it gives me an error.

我希望它具有%HoldLoc%值,但是由于遇到错误而一直对其进行硬编码.

I want this to have the %HoldLoc% value, but have been hard coding it because of errors I get.

环境是Windows 2008 R2服务器.

The environment is Windows 2008 R2 server.

我尝试过的变体,以及括号中是否带引号:

Variations I have tried, as well as with and without quotes in the parentheses:

FOR %F IN (%HoldLoc%)
FOR %F IN (%%HoldLock%) 
FOR %F IN (c:\Play\hold\*.tmp) 

我的代码:

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

echo on
set DataMax=20
set DataLoc=C:\Play\Data
Set HoldLoc=C:\Play\Hold
set count=0
FOR /F %%a in ('DIR /B %DataLoc%\*.tmp') do set /A count=count+1
if %count% GEQ %DataMax% (Goto Exit) else (GOTO FMove)
:FMove
Echo Gather Top 30 files
set SrcCount=0
set SrcMax=30
echo %HoldLoc%
FOR %F IN (c:\Play\hold\*.tmp) DO IF !SrcCount! LSS %SrcMax% (
    SET /A SrcCount += 1
    move /y %F  "%DataLoc%"
    )

问题是我在输出窗口中看到了它,为什么为什么不显示C?

Problem is that I get this in the output window, why won't the C be seen?

C:>set /A count=count+1

C:>if 19 GEQ 20 (Goto Exit )  else (GOTO FMove )

C:>Echo Gather Top 30 files
Gather Top 30 files

C:>set SrcCount=0

C:>set SrcMax=30

C:>echo C:\Play\Hold
C:\Play\Hold
\Play\hold\*.tmp) was unexpected at this time.

C:>FOR \Play\hold\*.tmp) DO IF !SrcCount! LSS 30 (

C:>

推荐答案

@echo off

set Source=C:\perl\Drift_Bat\IN
set Target=C:\perl\Drift_Bat\OUT

set MaxLimit=20

for /f "tokens=1* delims=[]" %%G in ('dir /A-D /B "%Source%\*.*" ^| find /v /n ""') do (
    move /y "%Source%\%%~nxH" "%Target%"
    if %%G==%MaxLimit% exit /b 0
)

这篇关于Windows批处理文件将X个文件从一个文件夹移动到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆