2014-10-30 40 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