[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

vbs to compress file

Posted on 2010-11-17
3
Medium Priority
?
533 Views
Last Modified: 2012-06-21
I have the code below that I obtained from EE, but it doesn't seem to work.   I want to be able to compress all the files in the "c:\prg" folder and run daily via scheduler.
strComputer = "chpcpsi.cmhhp.com"

dtmDate = Date - 1
strDay = Day(dtmDate)
If Len(strDay) < 2 Then
    strDay = "0" & strDay
End If
strMonth = Month(dtmDate)
If Len(strMonth) < 2 Then
    strMonth = "0" & strMonth
End If
strYear = Year(dtmDate)
strTargetDate = strYear & strMonth & strDay

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set FileList = objWMIService.ExecQuery _
( "ASSOCIATORS OF {Win32_Directory.Name='C:\prg'} Where " _
& "ResultClass = CIM_DataFile" )

For Each objFile In FileList
	strDate = Left(objFile.CreationDate, 8)
	If strDate < strTargetDate Then
		compress(objfile.name)
	End If
Next


MsgBox "done"



Function compress(strfile)
	Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set objFile = objWMI.Get("Cim_Datafile='" & strFile & "'")
	strerr = objFile.Compress
	If strerr <> 0 Then
		compress = strFile & " There was an error compressing the file: " & strerr
	Else
		compress = strfile & " File compression successful"
	End If
End Function

Open in new window

0
Comment
Question by:epicazo
[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
  • 2
3 Comments
 
LVL 5

Expert Comment

by:Kenneth Brown
ID: 34159456
Im not an expert in vbs, but try using tried & tested generic debugging techniques to narrow down the problem:
If you have the ability to display message boxes etc or some other means of communicating the program's flow, choose key points and display intermediate results so you can narrow down where the problem lies ( you have not said exactly what the problem is), eg are there any files in filelist etc...
Once you know where the problem is, you can fix it and then remove the debugging stuff....
0
 

Accepted Solution

by:
epicazo earned 0 total points
ID: 34199047
what I meant by "it doesn't seem to work" is that i don't see the compressed file anywhere.   I searched for it, and no luck.
0
 

Author Closing Comment

by:epicazo
ID: 34324355
No suitable solution found.   Closed
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

656 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