Solved

Windows Script Searching for files by date

Posted on 2011-03-17
5
475 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
  • 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 7

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 2003 domain controller crashed BDC is 2008 server 4 77
server DNS address could not be found 22 179
how to pick specific file from ftp 13 56
MS Endpoint Protection 2 21
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 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