Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zip & Files

Status
Not open for further replies.

spocker

Programmer
Jun 16, 2009
2
NL
Hello

Congratz for the forum, is very organized and helpful.

I have this program, search on folders and subfolders(only 2 levels of folders) and zip files to the zipfile with a similar name.

But because i have files with 50mb and others with 2,5Gb sometimes my program opens more than 1 winzip and i have 2 winzip aplications working in diferents files and the same ZipFile...

bd_lol_backup_20010100001.bak
bd_lol_backup_20010100023.bak

stays in the same zip bad_lol_backup.2001.01.zip!

It is possible my program to know when WinZip finish his task so he can pass to next file?!

Here is my code:

Code:
' Declarar Variaveis
' Fazer Ciclo de percorrer pastas
' Verificar se existe o Zip
' Se existe adicionar
' Se não criar e adicionar

Dim folder 'Folder mãe
Dim subFolders 'Folders seguintes
Dim objFSO
Dim zipFileName

folder = "Planning\"

set objFSO = CreateObject("Scripting.FileSystemObject") 
 
set objFolder = objFSO.getFolder(folder)

set subFolders = objFolder.SubFolders

'Ciclo que percorre todas as pastas
For each folderIdx In subFolders
	
	if (StrComp(folderIdx.Name,"report_baby_cliente_budget_backup_20080213")=0) Then 'Exception
		Set objFile = folderIdx.Files
		For each fileIdx In objFile
		If (StrComp(Right(fileIdx.Name,4),".bak")=0) Then
			Call CreateNameException(folderIdx.Name, fileIdx.Name)
			if (objFSO.FileExists(zipFileName)) Then 'Verificar se o Zip existe				
				Call ZipIt(folder&"\"&folderIdx.Name&"\"&fileIdx.Name, zipFileName)
			else
				'criar
				Call CreateZip(zipFileName) 'Se não passar daqui é porque 
										'provavelmente é um problema de permissões
				Call ZipIt(folder&"\"&folderIdx.Name&"\"&fileIdx.Name, zipFileName)				
			End If
		WScript.Sleep 20000
		End If
		Next
	else
	Set objFile = folderIdx.Files 'Ficheiros de cada pasta
	'Ciclo que percorre os ficheiros
	For each fileIdx In objFile
		If (StrComp(Right(fileIdx.Name,4),".bak")=0) Then
			Call CreateName(fileIdx.Name)
			if (objFSO.FileExists(zipFileName)) Then 'Verificar se o Zip existe				
				Call ZipIt(folder&"\"&folderIdx.Name&"\"&fileIdx.Name, zipFileName)
			else
				'criar
				Call CreateZip(zipFileName) 'Se não passar daqui é porque 
										'provavelmente é um problema de permissões
				Call ZipIt(folder&"\"&folderIdx.Name&"\"&fileIdx.Name, zipFileName)				
			End If
		End If
		WScript.Sleep 10000
	Next
	End if
	
Next

Sub CreateNameException(foldername, nameException)
	temp = Len(foldername)+7
	fileName = Left(nameException, temp)
	fileYear = Mid(nameException, temp+2,4)
	fileMonth = Mid(nameException, temp+6,2)
	
	zipFileName = folder&"\"&folderIdx.Name&"\"&fileName&"."&fileYear&"."&fileMonth&".zip"	
	
End Sub

Sub ZipIt(file,zip)
	Set oShell = WScript.CreateObject("WScript.Shell")
	oShell.Run "winzip32 -m " & zip & " " & file
End Sub


Sub CreateName(name)
	temp = InStr(name,"backup")
	fileName = Left(name,temp+5)
	fileYear = Mid(name,temp+7,4)
	fileMonth = Mid(name,temp+11,2)
	zipFileName = folder&"\"&folderIdx.Name&"\"&fileName&"."&fileYear&"."&fileMonth&".zip"	
	
End Sub

Sub CreateZip(zipFile)
	Call objFSO.CreateTextFile(zipFile, True)	
End Sub

Thank You in advance,
Spocker
 
Use Shell.Exec instead of Shell.run to start the process.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hello, thank you for your answer...

You are saying that all i have to do is change:

Code:
Sub ZipIt(file,zip)
    Set oShell = WScript.CreateObject("WScript.Shell")
    oShell.Run "winzip32 -m " & zip & " " & file
End Sub

by

Code:
Sub ZipIt(file,zip)
    Dim oExec

    Set oShell = WScript.CreateObject("WScript.Shell")
    Set oExec = oShell.Exec("winzip32 -m " & zip & " " & file)

    Do While oExec.Status = 0
          WScript.Sleep 100
    Loop
End Sub

So if i understand well... The Exec change the oExec.Status to a number different of 0 and so i will know when it finished the WinZip execution, is that it?!

Thank You,
Spocker


 
Correct. You may need to read the data int hat link a few times to have it fully sink in but that will be a big help to you once you do.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Have you tried this ?
oShell.Run "winzip32 -m " & zip & " " & file, , True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top