Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RE: Compressed files in VBScripts

557 views
Skip to first unread message

Umesh Thakur

unread,
Mar 13, 2006, 11:53:05 AM3/13/06
to
I could not find how to [un]compress a FILE using WMI (although there are
scripts to uncompress folders using Win32_Directory), but I found that it can
be done using COMPACT command.

Following is a sample code to do so:

dim fso, strFile
strFile = "d:\tempp\test.txt"

set fso=createObject("Scripting.fileSystemObject")
set wshShell = createObject("Wscript.Shell")
set fl = fso.getFile(strFile)
wscript.echo fl.attributes
if (fl.attributes AND 2048) then
wscript.echo "File is already compressed."
else
strCompactCmd = "%comspec% /c compact /c /f """ & strFile & """"
wscript.echo "Trying to compress..." & strCompactCmd
set objOut = wshShell.exec(strCompactCmd)
while objOut.status=0
wscript.sleep 1000
wend
strOP=objOut.StdOut.ReadAll()
if instr(1,strOP,"[OK]") = 0 then
wscript.echo "Error compressing file: " & strFile
'wscript.echo strOP
else
wscript.echo "File: " & strFile & " compressed successfully"
end if
end if
'--------------
when a file is compressed, output captured will contain a word "[OK]" that I
used to find whether file was compressed successfully or not.
Fore more information, see: compact /?

Hope, it helps.

Regards,
Umesh
-------
"Old programmers never die. They just terminate and stay resident."

"Guds" wrote:

> How to uncompress a compressed file using VBScripts. e.g to check if the file
> is compressed u use this line(if file.Attributes and 2048): but now I want to
> change that attribute to zero(uncompressed state)--
> Please help urgently

Umesh Thakur

unread,
Mar 13, 2006, 12:08:26 PM3/13/06
to
Sorry, I pasted the script to compress a file!
below is the right one, to uncompress a file...

dim fso, strFile
strFile = "d:\tempp\test.txt"

set fso=createObject("Scripting.fileSystemObject")
set wshShell = createObject("Wscript.Shell")
set fl = fso.getFile(strFile)

if (fl.attributes AND 2048) then

strCompactCmd = "%comspec% /c compact /u """ & strFile & """"
wscript.echo "Trying to uncompress...using command:" & strCompactCmd


set objOut = wshShell.exec(strCompactCmd)
while objOut.status=0
wscript.sleep 1000
wend
strOP=objOut.StdOut.ReadAll()
if instr(1,strOP,"[OK]") = 0 then

wscript.echo "Error uncompressing file: " & strFile
'wscript.echo strOP
else
wscript.echo "File: " & strFile & " uncompressed successfully"
end if
else
wscript.echo "File is not compressed, aborting uncompress operation."
end if

-----
Umesh

"Old programmers never die. They just terminate and stay resident."

Guds

unread,
Mar 14, 2006, 1:40:26 AM3/14/06
to
Thanka man this was so helpful cause now my script is working
--
Please help urgently
0 new messages