Solved

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

Posted on 2004-09-30
6
160 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
  • 3
  • 2
6 Comments
 
LVL 95

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 95

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

13 Experts available now in Live!

Get 1:1 Help Now