Solved

Windows Script Searching for files by date

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix/bash: scripted arithmetic 13 93
what is the performance monitor? How can we use it? 3 59
Shell Mail is not working 5 90
AWS CLI issues with Tags 3 63
I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
Learn about cloud computing and its benefits for small business owners.
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

18 Experts available now in Live!

Get 1:1 Help Now