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
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."