Solved

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

Posted on 2004-09-30
6
166 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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…
Multi-threading long-running processes can have a significant increase in overall performance and drastically decrease over time it takes for a process to complete. Unfortunately, not all applications support native multi-threading, some by design a…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

688 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