简体   繁体   English

批处理文件将超过30分钟的文件从一个文件夹复制到另一个文件夹

[英]batch file to copy files older than 30 minutes from one folder to another

如何将当前时间超过30分钟的文件从一个文件夹复制到另一个文件夹?

There are several Windows ports for the *nix find command available, offering switches like -mmin and -mtime that would be useful here, allowing the problem to be solved with a one-liner… 有几个Windows端口可供* nix find命令使用,提供-mmin-mtime等开关,这在这里很有用,可以通过单行解决问题...
Note that Powershell certainly is a viable alternative to achieve this goal . 请注意,Powershell当然是实现这一目标的可行替代方案。

In plain DOS, here is a rather limited batch script, but it suffices as a base to solve your problem: 在普通的DOS中,这是一个相当有限的批处理脚本,但它足以作为解决问题的基础:

@echo off
setlocal enabledelayedexpansion

call :GetRefTimestamp -30
for %%f in (*) do (
    call :GetFileTimestamp "%%~tf"
    if "!filetimestamp!" LSS "!reftimestamp!" echo -- %%f is older than 30 minutes
    if NOT "!filetimestamp!" LSS "!reftimestamp!" echo ++ %%f is NOT older than 30 minutes
)

endlocal
goto :EOF

:GetRefTimestamp
::get current date/time
for /f "usebackq tokens=1-5 delims=/:, " %%f in (`echo %DATE:~-10% %TIME: =0%`) do set reftimestamp=%%h%%g%%fT%%i%%j
::apply delta (format [-]HHMM) on time part - not handling over/underflow
set /a timedelta=%~1
set timedeltasign=
if %timedelta% LSS 0 set timedeltasign=-
set timeHHMM=%timestamp:~-4%
set /a timeHHMM+=timedelta
set /a timeMM=timeHHMM %% 100
if %timeMM% GEQ 60 set /a timeHHMM+=%timedeltasign%40
set timeHHMM=000%timeHHMM%
set reftimestamp=%reftimestamp:~0,-4%%timeHHMM:~-4%
goto :EOF

:GetFileTimestamp
::get file date/time
for /f "usebackq tokens=1-5 delims=/:, " %%f in (`echo %~1`) do set filetimestamp=%%h%%g%%fT%%i%%j
goto :EOF

Just use common sense for the delta (knowing the limitations) and refrain from using leading zeroes :] 只需使用delta的常识(知道限制)并避免使用前导零:]

The easiest way is to use robocopy (or forfiles) 最简单的方法是使用robocopy(或forfiles)

robocopy is part of win2003 rtk and is installed on vista and windows 7 by default -> http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en robocopy是win2003 rtk的一部分,默认安装在vista和Windows 7上 - > http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

FORFILES is part of Windows 2000/NT resource kit but works fine on XP/Vista/7 -> (I think it is not available on microsoft site anymore) FORFILES是Windows 2000 / NT资源工具包的一部分,但在XP / Vista / 7上工作正常 - >(我认为它不再在微软网站上提供)

h_ttp://www.petri.co.il/download_free_reskit_tools.htm h_ttp://www.petri.co.il/download_free_reskit_tools.htm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批处理脚本可将文件从scource移到目标文件夹,以保存30天以上的文件 - Batch script to move file from scource to destination folder for files older than 30 day 如何在批处理文件中将选定的文件从一个文件夹复制到另一个文件夹? - How to copy selected files from one folder to another in Batch file? 批处理文件将超过1年的文件移动到另一个文件夹 - Batch file to move file older than 1 year to another folder 用于将文件从一台服务器移动到另一台服务器超过 45 天的批处理脚本 - batch script to move files from one server to another older than 45 days 批处理文件可将文件从一个目录复制到另一个目录 - Batch file to copy files from one directory to another 用于将超过 30 天且具有特定扩展名的文件移动到另一个文件夹的 Windows 脚本 - Windows Script to move files older than 30 days with a specific extension to another folder Windows批处理文件:使用UnixUtils find命令将X分钟之前的文件移动到其他目录 - Windows batch file: move files older than X minutes to a different directory using UnixUtils find command 使用Windows批处理文件将多个文件从具有相同文件名的不同文件夹复制到一个公用文件夹 - Copy multiple files from different folder with same filename to one common folder using windows batch file 批处理文件,仅将每个子文件夹的文件类型之一复制到另一个文件夹 - batch file to copy only one of filetype for each subfolder to another folder 批处理文件以递归方式删除超过N天的文件夹中的文件 - Batch file to recursively delete files in a folder older than N number of days
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM