Solved

Windows Script Searching for files by date

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now