2014-10-30 90 views
0

我使用批处理文件在每次移动的5个文件1集到一个特定的顺序到一个临时目录中有一个自动化过程中地方然后这个文件的移动之前执行的操作到下一个文件。该过程是成功的,直到发生下面的新情况。批处理脚本文件移动对多种方案

新的情况是,随机 - 通常周一 - 有各5个文件的多次出现(通常发生这种情况时有2台)。我需要搞清楚的是如何将它们移动的顺序 - 即上述action--说明,以便在电视机1中的文件移动设置2个文件前移到一个-AT-A-时间。

的这些文件的命名方式如下样本:该文件的样本列表下方收到

日期为20141028.

Set 1 
file_asia1.txt.20141026 
file_asia2.txt.20141026 
file_euro.txt.20141024 
file_lamr.txt.20141024 
file_namr.txt.20141024 

Set 2 
file_asia1.txt.20141027 
file_asia2.txt.20141027 
file_euro.txt.20141026 
file_lamr.txt.20141026 
file_namr.txt.20141026 

我需要每一个文件移动在集1,然后继续设置2.我试图研究这一点,但无法找到满足上述要求的任何实例。

请帮忙!

回答

0
@echo off 
    setlocal enableextensions disabledelayedexpansion 

    rem Configure paths 
    set "sourceFolder=c:\some\where" 
    set "targetFolder=d:\other\somewhere" 

    rem Configure the required files in the correct order 
    set fileSet="file_asia1.txt" "file_asia2.txt" "file_euro.txt" "file_lamr.txt" "file_namr.txt" 

:loop 
    rem Check it there is a file for each defined element in the set. If not, leave 
    for %%a in (%fileSet%) do dir /b /a-d "%sourceFolder%\%%~a*" >nul 2>nul || goto :eof 

    rem We have files, continue the process 
    rem For each file in the set, find the first matching one and process it 
    for %%a in (%fileSet%) do (
     set "first=" 
     for /f "delims=" %%b in (' 
      dir /b /a-d /on "%sourceFolder%\%%~a*" 
     ') do if not defined first (
      set "first=1" 
      echo processing %%~b 
      move /y "%sourceFolder%\%%~b" "%targetFolder%" >nul 
      rem Do what needs to be done 
      rem .... 
     ) 
    ) 

    rem Go test for another set of files 
    goto :loop