From: AHartman on
I'm using this script to capture files I want to Zip but when the Zip
process start I get a File in use by another process message.

Need some help on where I need to close my file.

Option explicit

Dim strPath, strCmd, strFile, strFileStem, strZipFile, strLogFile,strCapFile
Dim objFSO, objShell, objLogFile,objCapFile

Dim dNow, yy, mt, dd, hh, nn, ss, ZipFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject ("WScript.shell")

dNow = Now

yy = Right(Year(dNow), 2)
mt = Right("00" & Month(dNow), 2)
dd = Right("00" & Day(dNow), 2)


hh = Right("00" & Hour(dNow), 2)
nn = Right("00" & Minute(dNow), 2)
ss = Right("00" & Second(dNow), 2)


ZipFile = "Send" & yy & mt & dd & hh & nn & ss


'
' Logging this run
'
strLogFile = "C:\temp\"+WScript.ScriptName+".log"
Set objLogFile = objFSO.OpenTextFile(strLogFile, 2, true )
objLogFile.WriteLine(WScript.ScriptName & " started.")


'
' Capture files to zip
'
strCapFile = "C:\SourceFolder\ziplist"+".log"
Set objCapFile = objFSO.OpenTextFile(strCapFile, 2, true )




strPath = "C:\sourcefolder"


objLogFile.WriteLine(strPath)

If objFSO.FolderExists(strPath) Then

Dim f, objFile, fileCollection
Set f = objFSO.GetFolder(strPath)
Set fileCollection = f.Files
For Each objFile in fileCollection
'msgbox objfile
strFile = objFile.name
If UCase(Right(strFile, 3)) = "PS1" then
'If DateDiff("h", objFile.DateLastModified, Now) > 0 then
objLogFile.WriteLine("Zipping")+ " " +strPath+"\"+strFile
objCapfile.writeline(strFile)



'End if
End if
Next
else
Wscript.echo "path not found: "+ strPath
End if

'
' Zip the file
'
'

strcmd = "%comspec% /c C:\winRar\rar a " + "-n@" + strCapfile + " " +
ZipFile
objLogFile.WriteLine(strCmd)
objShell.run strCmd ,7 , true


Set objShell = Nothing
set objFSO = nothing

objLogFile.WriteLine("ending")
objLogFile.WriteLine(WScript.ScriptName & " ended.")
objLogFile.close()

Thanks.

From: urkec on
"AHartman" wrote:

> I'm using this script to capture files I want to Zip but when the Zip
> process start I get a File in use by another process message.
>
> Need some help on where I need to close my file.
>
> Option explicit
>
> Dim strPath, strCmd, strFile, strFileStem, strZipFile, strLogFile,strCapFile
> Dim objFSO, objShell, objLogFile,objCapFile
>
> Dim dNow, yy, mt, dd, hh, nn, ss, ZipFile
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objShell = WScript.CreateObject ("WScript.shell")
>
> dNow = Now
>
> yy = Right(Year(dNow), 2)
> mt = Right("00" & Month(dNow), 2)
> dd = Right("00" & Day(dNow), 2)
>
>
> hh = Right("00" & Hour(dNow), 2)
> nn = Right("00" & Minute(dNow), 2)
> ss = Right("00" & Second(dNow), 2)
>
>
> ZipFile = "Send" & yy & mt & dd & hh & nn & ss
>
>
> '
> ' Logging this run
> '
> strLogFile = "C:\temp\"+WScript.ScriptName+".log"
> Set objLogFile = objFSO.OpenTextFile(strLogFile, 2, true )
> objLogFile.WriteLine(WScript.ScriptName & " started.")
>
>
> '
> ' Capture files to zip
> '
> strCapFile = "C:\SourceFolder\ziplist"+".log"
> Set objCapFile = objFSO.OpenTextFile(strCapFile, 2, true )
>
>
>
>
> strPath = "C:\sourcefolder"
>
>
> objLogFile.WriteLine(strPath)
>
> If objFSO.FolderExists(strPath) Then
>
> Dim f, objFile, fileCollection
> Set f = objFSO.GetFolder(strPath)
> Set fileCollection = f.Files
> For Each objFile in fileCollection
> 'msgbox objfile
> strFile = objFile.name
> If UCase(Right(strFile, 3)) = "PS1" then
> 'If DateDiff("h", objFile.DateLastModified, Now) > 0 then
> objLogFile.WriteLine("Zipping")+ " " +strPath+"\"+strFile
> objCapfile.writeline(strFile)
>
>
>
> 'End if
> End if
> Next
> else
> Wscript.echo "path not found: "+ strPath
> End if
>
> '
> ' Zip the file
> '
> '
>
> strcmd = "%comspec% /c C:\winRar\rar a " + "-n@" + strCapfile + " " +
> ZipFile
> objLogFile.WriteLine(strCmd)
> objShell.run strCmd ,7 , true
>
>
> Set objShell = Nothing
> set objFSO = nothing
>
> objLogFile.WriteLine("ending")
> objLogFile.WriteLine(WScript.ScriptName & " ended.")
> objLogFile.close()
>
> Thanks.
>
>

You need to close the file after you write in the file names and before you
use it with rar.exe:


If UCase(Right(strFile, 3)) = "PS1" then
'If DateDiff("h", objFile.DateLastModified, Now) > 0 then
objLogFile.WriteLine("Zipping")+ " " +strPath+"\"+strFile
objCapfile.writeline(strFile)

'End if
End if
Next
else
Wscript.echo "path not found: "+ strPath
End if

'Close ziplist.log
objCapfile.Close

'
' Zip the file
'
'

strcmd = "%comspec% /c C:\winRar\rar a " + "-n@" + strCapfile + " " + ZipFile
objLogFile.WriteLine(strCmd)
objShell.run strCmd ,7 , true


Maybe you don't neet to create that file at all , using something like this
instead:

strcmd = "%comspec% /c C:\winRar\rar a -ep " + ZipFile + "
c:\SourceFolder\*.ps1"

(I don't use Winrar much, so I'm not sure that is exactly what you want)

--
urkec
From: AHartman on
Thanks.


"urkec" <urkec(a)discussions.microsoft.com> wrote in message
news:9CDEB0F4-27FF-4082-B77B-6EA31551759B(a)microsoft.com...
> "AHartman" wrote:
>
>> I'm using this script to capture files I want to Zip but when the Zip
>> process start I get a File in use by another process message.
>>
>> Need some help on where I need to close my file.
>>
>> Option explicit
>>
>> Dim strPath, strCmd, strFile, strFileStem, strZipFile,
>> strLogFile,strCapFile
>> Dim objFSO, objShell, objLogFile,objCapFile
>>
>> Dim dNow, yy, mt, dd, hh, nn, ss, ZipFile
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objShell = WScript.CreateObject ("WScript.shell")
>>
>> dNow = Now
>>
>> yy = Right(Year(dNow), 2)
>> mt = Right("00" & Month(dNow), 2)
>> dd = Right("00" & Day(dNow), 2)
>>
>>
>> hh = Right("00" & Hour(dNow), 2)
>> nn = Right("00" & Minute(dNow), 2)
>> ss = Right("00" & Second(dNow), 2)
>>
>>
>> ZipFile = "Send" & yy & mt & dd & hh & nn & ss
>>
>>
>> '
>> ' Logging this run
>> '
>> strLogFile = "C:\temp\"+WScript.ScriptName+".log"
>> Set objLogFile = objFSO.OpenTextFile(strLogFile, 2, true )
>> objLogFile.WriteLine(WScript.ScriptName & " started.")
>>
>>
>> '
>> ' Capture files to zip
>> '
>> strCapFile = "C:\SourceFolder\ziplist"+".log"
>> Set objCapFile = objFSO.OpenTextFile(strCapFile, 2, true )
>>
>>
>>
>>
>> strPath = "C:\sourcefolder"
>>
>>
>> objLogFile.WriteLine(strPath)
>>
>> If objFSO.FolderExists(strPath) Then
>>
>> Dim f, objFile, fileCollection
>> Set f = objFSO.GetFolder(strPath)
>> Set fileCollection = f.Files
>> For Each objFile in fileCollection
>> 'msgbox objfile
>> strFile = objFile.name
>> If UCase(Right(strFile, 3)) = "PS1" then
>> 'If DateDiff("h", objFile.DateLastModified, Now) > 0 then
>> objLogFile.WriteLine("Zipping")+ " " +strPath+"\"+strFile
>> objCapfile.writeline(strFile)
>>
>>
>>
>> 'End if
>> End if
>> Next
>> else
>> Wscript.echo "path not found: "+ strPath
>> End if
>>
>> '
>> ' Zip the file
>> '
>> '
>>
>> strcmd = "%comspec% /c C:\winRar\rar a " + "-n@" + strCapfile + " " +
>> ZipFile
>> objLogFile.WriteLine(strCmd)
>> objShell.run strCmd ,7 , true
>>
>>
>> Set objShell = Nothing
>> set objFSO = nothing
>>
>> objLogFile.WriteLine("ending")
>> objLogFile.WriteLine(WScript.ScriptName & " ended.")
>> objLogFile.close()
>>
>> Thanks.
>>
>>
>
> You need to close the file after you write in the file names and before
> you
> use it with rar.exe:
>
>
> If UCase(Right(strFile, 3)) = "PS1" then
> 'If DateDiff("h", objFile.DateLastModified, Now) > 0 then
> objLogFile.WriteLine("Zipping")+ " " +strPath+"\"+strFile
> objCapfile.writeline(strFile)
>
> 'End if
> End if
> Next
> else
> Wscript.echo "path not found: "+ strPath
> End if
>
> 'Close ziplist.log
> objCapfile.Close
>
> '
> ' Zip the file
> '
> '
>
> strcmd = "%comspec% /c C:\winRar\rar a " + "-n@" + strCapfile + " " +
> ZipFile
> objLogFile.WriteLine(strCmd)
> objShell.run strCmd ,7 , true
>
>
> Maybe you don't neet to create that file at all , using something like
> this
> instead:
>
> strcmd = "%comspec% /c C:\winRar\rar a -ep " + ZipFile + "
> c:\SourceFolder\*.ps1"
>
> (I don't use Winrar much, so I'm not sure that is exactly what you want)
>
> --
> urkec

From: AHartman on

It creates the Zip file but only one file is in it not the 4 it should
picked up?



"urkec" <urkec(a)discussions.microsoft.com> wrote in message
news:9CDEB0F4-27FF-4082-B77B-6EA31551759B(a)microsoft.com...
> "AHartman" wrote:
>
>> I'm using this script to capture files I want to Zip but when the Zip
>> process start I get a File in use by another process message.
>>
>> Need some help on where I need to close my file.
>>
>> Option explicit
>>
>> Dim strPath, strCmd, strFile, strFileStem, strZipFile,
>> strLogFile,strCapFile
>> Dim objFSO, objShell, objLogFile,objCapFile
>>
>> Dim dNow, yy, mt, dd, hh, nn, ss, ZipFile
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objShell = WScript.CreateObject ("WScript.shell")
>>
>> dNow = Now
>>
>> yy = Right(Year(dNow), 2)
>> mt = Right("00" & Month(dNow), 2)
>> dd = Right("00" & Day(dNow), 2)
>>
>>
>> hh = Right("00" & Hour(dNow), 2)
>> nn = Right("00" & Minute(dNow), 2)
>> ss = Right("00" & Second(dNow), 2)
>>
>>
>> ZipFile = "Send" & yy & mt & dd & hh & nn & ss
>>
>>
>> '
>> ' Logging this run
>> '
>> strLogFile = "C:\temp\"+WScript.ScriptName+".log"
>> Set objLogFile = objFSO.OpenTextFile(strLogFile, 2, true )
>> objLogFile.WriteLine(WScript.ScriptName & " started.")
>>
>>
>> '
>> ' Capture files to zip
>> '
>> strCapFile = "C:\SourceFolder\ziplist"+".log"
>> Set objCapFile = objFSO.OpenTextFile(strCapFile, 2, true )
>>
>>
>>
>>
>> strPath = "C:\sourcefolder"
>>
>>
>> objLogFile.WriteLine(strPath)
>>
>> If objFSO.FolderExists(strPath) Then
>>
>> Dim f, objFile, fileCollection
>> Set f = objFSO.GetFolder(strPath)
>> Set fileCollection = f.Files
>> For Each objFile in fileCollection
>> 'msgbox objfile
>> strFile = objFile.name
>> If UCase(Right(strFile, 3)) = "PS1" then
>> 'If DateDiff("h", objFile.DateLastModified, Now) > 0 then
>> objLogFile.WriteLine("Zipping")+ " " +strPath+"\"+strFile
>> objCapfile.writeline(strFile)
>>
>>
>>
>> 'End if
>> End if
>> Next
>> else
>> Wscript.echo "path not found: "+ strPath
>> End if
>>
>> '
>> ' Zip the file
>> '
>> '
>>
>> strcmd = "%comspec% /c C:\winRar\rar a " + "-n@" + strCapfile + " " +
>> ZipFile
>> objLogFile.WriteLine(strCmd)
>> objShell.run strCmd ,7 , true
>>
>>
>> Set objShell = Nothing
>> set objFSO = nothing
>>
>> objLogFile.WriteLine("ending")
>> objLogFile.WriteLine(WScript.ScriptName & " ended.")
>> objLogFile.close()
>>
>> Thanks.
>>
>>
>
> You need to close the file after you write in the file names and before
> you
> use it with rar.exe:
>
>
> If UCase(Right(strFile, 3)) = "PS1" then
> 'If DateDiff("h", objFile.DateLastModified, Now) > 0 then
> objLogFile.WriteLine("Zipping")+ " " +strPath+"\"+strFile
> objCapfile.writeline(strFile)
>
> 'End if
> End if
> Next
> else
> Wscript.echo "path not found: "+ strPath
> End if
>
> 'Close ziplist.log
> objCapfile.Close
>
> '
> ' Zip the file
> '
> '
>
> strcmd = "%comspec% /c C:\winRar\rar a " + "-n@" + strCapfile + " " +
> ZipFile
> objLogFile.WriteLine(strCmd)
> objShell.run strCmd ,7 , true
>
>
> Maybe you don't neet to create that file at all , using something like
> this
> instead:
>
> strcmd = "%comspec% /c C:\winRar\rar a -ep " + ZipFile + "
> c:\SourceFolder\*.ps1"
>
> (I don't use Winrar much, so I'm not sure that is exactly what you want)
>
> --
> urkec