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\
The files have the extensions of .doc
and .xls
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:
Due to the syntax you used for the source directory path (
\\folder1\
) I suppose it is given by a UNC path. So I use thepushd
command which understands such, maps it to a temporary drive it creates and changes the current working directory to the root of that drive.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). Sinceforfiles
supports a single mask only, I simply use it twice.The
popd
command at the end removes that temporary drive which has been created bypushd
.For more details about each used command, type it into the command prompt, followed by
/?
.Below code can do the required.I just added comments here to explain the code here.