Solved

Windows Script Searching for files by date

Posted on 2011-03-17
5
477 Views
Last Modified: 2012-05-11
Hi all,

I'm coming up with a script to run on our file server that will find and move (as in copy to new location then delete the original) all files within a shared directory that were last accessed before 01/01/2009 (so anything 12/31/2008 or earlier would be moved.) We will then archive all the moved files offsite.

So far, my script will just be a simple batch file using the FORFILES command, as seen below. Please keep in mind I'm trying to teach myself batch scripting, so if I'm headed in the right direction, please don't give me everything I need in one fell swoop! (I still need to work on my /C argument, obviously.)

So to sum up my current question, the /D command will search by date last modified, but is there a way to search by date last accessed?

FORFILES /S /P C:\PATH_TO_BACKUP /D -12/31/2008 /C "cmd /c echo @file"

Thanks!
0
Comment
Question by:biofishfreak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
rorybreen earned 125 total points
ID: 35160756
Hello,

I'm not sure if this is exactly what your after as it's a GUI...

http://www.nirsoft.net/utils/bulk_file_changer.html
0
 
LVL 8

Expert Comment

by:Murugesan Nagarajan
ID: 35163710
An example BATCH code:
echo off & setLocal EnableDELAYedExpansion
PUSHD Y:\DIR1\DIR2\
SET source=Y:\DIR1\SUBDIR1\
SET dest="F:\DIR1\SUBDIR1\"
for /f "tokens=* delims= " %%a in ('dir/s/b/ad') do (
pushd "%%a"
if not exist "!dest!%%a" md "!dest!%%a"
:: or: md "!dest!%%a" 2>nul
for /f "tokens=* delims= " %%b in ('dir/b/a-d') do (
set year=%%~Tb
:: ASSuming filedate looks like 01/02/2009
set year=!year:~6,4!
IF "!year!" NEQ "2010" >>F:\MOVE.bat ECHO MOVE /Y "!source!!FILE!" "!dest!%%a"
)
)
:: safetied off until verified
echo examine the batchfile...
more F:\move.bat

Open in new window


which is available at the following location:
http://www.computing.net/answers/programming/move-files-based-on-date-modified/20853.html

The mentioned url describes about XXCOPY  and other informations.
0
 
LVL 3

Author Comment

by:biofishfreak
ID: 35183377
Thanks for the prompt responses, but murugesandins, that script is still looking at the date modified meta data, and I need to look at the date last accessed.

Rorybreen, that software actually looks pretty promising... but I'd still prefer a script of some sort, but that might work.

I'm going to keep digging for the time being, and hope to come up with something. Also, I'm over the "learning" part of the script, and if someone finds a full script to accomplish what I want, I'll take it! :-)
0
 
LVL 5

Expert Comment

by:rorybreen
ID: 35190936
Maybe find a utility to make the modified date the same as the last accessed date, that may be an approach for you.
0
 
LVL 3

Author Closing Comment

by:biofishfreak
ID: 35191949
While not a script, the nirsoft bulk file changer does everything I need. Thanks for the prompt response!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question