Solved

How to automatically zip files not accessed for specified time & remove uncompressed file

Posted on 2004-09-30
6
165 Views
Last Modified: 2010-04-14
hi

Is there some additional software / script that could be run that can check the 'Last Accessed' attribute of files and Zip old items and remove the uncompressed file?  The computer is a Windows 2000 Server.  

Thanks for any pointers

Rob
0
Comment
Question by:robjeeves
[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
  • 3
  • 2
6 Comments
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 12197334
I believe this will do what you seek:

(It's late and I haven't tested it thoroughly, so be careful

-------8<----------------
@echo off
for /f "usebackq tokens=1,5" %%a in (`dir /a-d /ta | find /i "/"`) do (
if "%%a" GEQ "%1" (
      zip %2 %%a
      del %%a
)
)
-------8<------------------

Requires usage as such:

scriptname.cmd date file.zip

For example, all files accessed since 9/15/04 would result in running the script with the following parameters:

scriptname 09/15/2004 file.zip
0
 
LVL 9

Author Comment

by:robjeeves
ID: 12197516
That looks great.  Trouble is I have no idea how to use it :-)

I should of indicated my level of scripting knowledge (none) before asking for a script.  How do I use this script i.e Execute it

Rob
0
 
LVL 2

Expert Comment

by:demingj1
ID: 12201122
1. create a new .txt file and rename it scriptname.bat

2. paste that code in a the called scriptname.bat

3. Start -> Run : "cmd.exe"

4. "cd" to directory w/ script in it

5. now:
prompt> scriptname.bat 9/15/04 file.zip
to run it

I can't read the script syntax well enough to tell which files will be .zipped from there, be careful, it may be just files in that directory and below or it may be all files on your machine.
0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
LVL 96

Accepted Solution

by:
Lee W, MVP earned 50 total points
ID: 12201608
I MADE AN ERROR IN THE SCRIPT!!!

the line that reads
   zip %2 %%a

SHOULD read
   zip %2 %%b

To explain in more detail, the for command cycles through each entry found when performing a DIR /A-D /TA (/a-d = all files except directories; /ta = time displayed is last accessed; do a dir /? from a command prompt for more info on the DIR command).  Further, the FIND /I "/" looks through the results of the DIR /A-D /TA command to find only lines with "/" in them - in this case, it will be anything with a date, since dates are formatted MM/DD/YYYY.

For each entry found, it then does a check - if "%%a" (the first token from the DIR command executed before, which happens to be the date) is GEQ (Greater then or EQual to) %1 which is the first parameter entered when executing the script and must be in the identical form of the dates listed when doing the dir (meaning you MUST enter the date as 09/15/2004 - entering them in 9/15/04 won't likely work, nor will 09-15-2004.  It MUST BE in the form of 09/15/2004.

So anyway, if "%%a" = "%1" Then it executes a ZIP program (NOT included with windows - there's a freeware ZIP utility called ZIP and ZIP16 that works much like PKZIP, but I'm moving and the computer with the bookmark is currently unavailable).  In any case, %2 is the file name - the SECOND parameter specified when entering the script.  So ZIP %2 %%b  should add the file name (%%b, the 5th token) to the zip file named %2.

tokens are numbered, 1-?, each one seperated by either tab(s) or spaces(s), by default - other tokens can be specified, but my sample aren't.
If your directory listing read ... then tokens would be:

10/01/2004  12:49 AM               125 la.cmd
09/12/2004  11:43 AM            11,808 gbmail.exe
09/12/2004  11:34 AM               286 getversion.cmd
09/12/2004  11:34 AM                30 Null
09/12/2004  11:45 AM             3,316 xcopy.help

If you execute the script as "scriptname 09/15/2004 file.zip", then the script would actually read:

for /f "usebackq tokens=1,5" %%a in (`dir /a-d /ta | find /i "/"`) do (
if "10/01/2004" GEQ "09/15/2004" (
     zip file.zip la.cmd
     del la.cmd
)
)


the for would actually run the if comparison once for each file listed.  The example above is only one comparison.
0
 
LVL 9

Author Comment

by:robjeeves
ID: 12222278
Thanks for such a detailed explaination.  I will give this a try this week.

Rob
0
 
LVL 9

Author Comment

by:robjeeves
ID: 12478991
THanks very much for you input on the Question.  We actually don't require solution anymore but thanks again for advice.

Rob
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
A hard and fast method for reducing Active Directory Administrators members.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

734 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