2015-06-10 23 views
2

新文件創建時間爲20分鐘後我想將文件夾New中的所有擴展名爲.txt的文件複製到文件夾Target。 (我想複製olny文件超過20分鐘以上)批處理 - xcopy文件早於x分鐘

到目前爲止,它看起來像這樣:

set hh=%TIME:~0,2% 
set mm=%TIME:~3,2% 
set ss=%TIME:~6,2% 

set /a sum_sec=%hh% * 3600 + %mm% * 60 + %ss% -300 

set /a h=%sum_sec%/3600 
set /a m=(%sum_sec%/60) - 60 * %h% 
set /a s=%sum_sec% - 60 * (%sum_sec%/60) 
IF %h% LSS 10 set h=0%h% 
IF %m% LSS 10 set m=0%m% 
IF %s% LSS 10 set s=0%s% 

set new_time=%h%:%m%:%s% 

到目前爲止,我只能刪除舊的20多分鐘的文件:

forfiles /P "C:\Users\Desktop\Start" /S /M *.txt /C "cmd /c if @ftime LSS %new_time% del /F /Q @path" 

我現在的問題是如何從文件夾複製New新文件,20分鐘後到文件夾Target

最佳的REG

+0

更舊的意思是創建或修改? – npocmaka

+0

嗨。在創造的意義上更古老。 – BASF

回答

2

檢查FileTimeFilter.bat - 它能夠通過不同的時間conditions.So過濾文件(它應該是在同一個目錄):

@echo off 
for /f "tokens=* delims=" %%# in (' 
    call FileTimeFiler.bat "New" -mm -20 -direction before -filetime created 
') do (
    copy "%%~f#" "Target" 
) 

編輯。篩選txt文件

@echo off 
for /f "tokens=* delims=" %%# in (' 
    call FileTimeFiler.bat "New" -mm -20 -direction before -filetime created ^| findstr /e /i ".txt" 
') do (
    copy "%%~f#" "Target" 
) 
+0

不錯的批處理文件,thx分享! – BASF

+0

嗨。是否有可能搜索並只複製擴展名爲.txt的文件?我嘗試''C:\ Users \ Desktop \ New \ *。txt「-mm -20-direction before -filetime created' 但是它失敗並且得到運行時錯誤。 – BASF

+0

@BASF - 檢查我的編輯。 – npocmaka

相關問題