Windows脚本将具有特定扩展名的30天以上的文件移动到另一个文件夹 [英] Windows Script to move files older than 30 days with a specific extension to another folder

查看:273
本文介绍了Windows脚本将具有特定扩展名的30天以上的文件移动到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Windows Server的脚本,最好是vbscript,它将一个文件夹中的文件归档到另一个文件夹.从\\folder1\\\folder1\archive\

I am in need of a script preferably a vbscript for a Windows Server which will archive files in a folder to another folder. Say from \\folder1\ to \\folder1\archive\

文件的扩展名为.doc.xls

但是我也只想移动30天以上的文件.

But also I only want to move files older than 30 days.

有没有简单的方法可以做到这一点?

Is there a simple way to do this?

推荐答案

因为您使用,我想您也正在接受批处理文件解决方案.
您在这里:

Since you tagged your question with batch-file, I suppose you are accepting batch file solutions too.
Here you are:

pushd \\folder1
forfiles /M *.doc /D -30 /C "cmd /C if @isdir==FALSE move @file .\archive\"
forfiles /M *.xls /D -30 /C "cmd /C if @isdir==FALSE move @file .\archive\"
popd

由于您用于源目录路径(\\folder1\)的语法,我想它是由UNC路径给出的.因此,我使用pushd命令理解该命令,将其映射到它创建的临时驱动器,然后将当前工作目录更改为该驱动器的根目录.

Due to the syntax you used for the source directory path (\\folder1\) I suppose it is given by a UNC path. So I use the pushd command which understands such, maps it to a temporary drive it creates and changes the current working directory to the root of that drive.

forfiles命令能够枚举给定的目录(树),并遍历满足特定掩码和修改日期(年龄)的所有项目.由于forfiles仅支持单个蒙版,因此我只使用了两次.

The forfiles command is capable of enumerating a given directory (tree) and iterates through all items that meet a certain mask and modification date (age). Since forfiles supports a single mask only, I simply use it twice.

最后的popd命令将删除由pushd创建的临时驱动器.

The popd command at the end removes that temporary drive which has been created by pushd.

有关每个使用的命令的更多详细信息,请在命令提示符下键入它,然后按/?.

For more details about each used command, type it into the command prompt, followed by /?.

这篇关于Windows脚本将具有特定扩展名的30天以上的文件移动到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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