Window Zip Using OLEObject In PowerBuilder
Create Object nvo_winzip:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
forward global type nvo_winzip from nonvisualobject end type end forward global type nvo_winzip from nonvisualobject autoinstantiate end type type prototypes Subroutine SleepMS ( ulong dwMilliseconds ) Library "kernel32.dll" Alias For "Sleep" end prototypes forward prototypes public function integer of_addfolderzip (string as_folder, string as_zipfile) public function integer of_unzip (string as_unzipfile, string as_unzipfolder) public function integer of_addzip (string as_file, string as_zipfile, boolean ab_append) public function integer of_addzip (string as_file, string as_zipfile) end prototypes public function integer of_addfolderzip (string as_folder, string as_zipfile);//==================================================================== // Function: nvo_winzip.of_addfolderzip() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_folder // value string as_zipfile //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/03/24 //-------------------------------------------------------------------- // Usage: nvo_winzip.of_addfolderzip ( string as_folder, string as_zipfile ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== OleObject oZipShell, oZipFSO, oNewZipFile, oZip, oFolder Int li_rc String ls_ZipFile, ls_Folder ls_Folder = as_folder ls_ZipFile = as_zipfile If IsNull(ls_Folder) Or Len(Trim(ls_Folder)) = 0 Then MessageBox("Warning", "Folder To Zip IsNull Or Empty") Return -1 End If If IsNull(ls_ZipFile) Or Len(Trim(ls_ZipFile)) = 0 Then MessageBox("Warning", "Zip File IsNull Or Empty") Return -1 End If If not DirectoryExists(ls_Folder) Then MessageBox("Warning", "Folder Not Exists") Return -1 End If Try //Create Oleobject oZipShell = Create OleObject li_rc = oZipShell.ConnectToNewObject ( "Shell.Application") If li_rc < 0 Then MessageBox("Warning", "ConnectToNewObject Shell.Application") Destroy oZipShell Return -1 End If oZipFSO = Create OleObject li_rc = oZipFSO.ConnectToNewObject ("Scripting.FileSystemObject" ) If li_rc < 0 Then MessageBox("Warning", "ConnectToNewObject Scripting.FileSystemObject") Destroy oZipFSO Return -1 End If //That zip file already exists - deleting it. If oZipFSO.FileExists(ls_ZipFile) Then oZipFSO.DeleteFile (ls_ZipFile) End If //Create File If Not oZipFSO.FileExists(ls_ZipFile) Then oNewZipFile = Create OleObject oNewZipFile = oZipFSO.CreateTextFile(ls_ZipFile) oNewZipFile.Close End If //Add File oZip = oZipShell.NameSpace(ls_ZipFile) oFolder = oZipShell.NameSpace(ls_Folder) oZip.Copyhere( ls_Folder, 4) /* //Keep script waiting until Compressing is done Do While oFolder.Items.Count > oZip.Items.Count SleepMS(500) Loop */ Catch (runtimeerror e) String ls_msg ls_msg = e.getMessage() MessageBox("Warning", ls_msg) Destroy oZipShell Destroy oZipFSO Destroy oNewZipFile Destroy oZip Return -1 End Try Destroy oZipShell Destroy oZipFSO Destroy oNewZipFile Destroy oZip Return 0 end function public function integer of_unzip (string as_unzipfile, string as_unzipfolder);//==================================================================== // Function: nvo_winzip.of_unzip() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_unzipfile // value string as_unzipfolder //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/03/24 //-------------------------------------------------------------------- // Usage: nvo_winzip.of_unzip ( string as_unzipfile, string as_unzipfolder ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== OleObject oZipShell, oUnzipFSO Int li_rc String ls_UnZipFile, ls_UnZipfolder ls_UnZipfolder = as_UnZipfolder ls_UnZipFile = as_UnZipFile If IsNull(ls_UnZipfolder) Or Len(Trim(ls_UnZipfolder)) = 0 Then MessageBox("Warning", "Folder UnZip IsNull Or Empty") Return -1 End If If IsNull(ls_UnZipFile) Or Len(Trim(ls_UnZipFile)) = 0 Then MessageBox("Warning", "Zip File IsNull Or Empty") Return -1 End If Try //Create Oleobject oZipShell = Create OleObject li_rc = oZipShell.ConnectToNewObject ( "Shell.Application") If li_rc < 0 Then MessageBox("Warning", "ConnectToNewObject Shell.Application") Destroy oZipShell Return -1 End If oUnzipFSO = Create OleObject li_rc = oUnzipFSO.ConnectToNewObject ("Scripting.FileSystemObject" ) If li_rc < 0 Then MessageBox("Warning", "ConnectToNewObject Scripting.FileSystemObject") Destroy oUnzipFSO Return -1 End If //Create Directory Destination If Not oUnzipFSO.FolderExists(ls_UnZipfolder) Then oUnzipFSO.CreateFolder(ls_UnZipfolder) End If oZipShell.NameSpace(ls_UnZipfolder).Copyhere (oZipShell.NameSpace(ls_UnZipFile).Items) Catch (runtimeerror e) String ls_msg ls_msg = e.getMessage() MessageBox("Warning", ls_msg) Destroy oZipShell Destroy oUnzipFSO Return -1 End Try Destroy oZipShell Destroy oUnzipFSO Return 0 end function public function integer of_addzip (string as_file, string as_zipfile, boolean ab_append);//==================================================================== // Function: nvo_winzip.of_addzip() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_file // value string as_zipfile // value boolean ab_append //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/03/24 //-------------------------------------------------------------------- // Usage: nvo_winzip.of_addzip ( string as_file, string as_zipfile, boolean ab_append ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== OleObject oZipShell, oZipFSO, oNewZipFile, oZip Int li_rc String ls_ZipFile, ls_File Long ll_ZipFileCount ls_File = as_file ls_ZipFile = as_zipfile If IsNull(ls_File) Or Len(Trim(ls_File)) = 0 Then MessageBox("Warning", "File To Zip IsNull Or Empty") Return -1 End If If IsNull(ls_ZipFile) Or Len(Trim(ls_ZipFile)) = 0 Then MessageBox("Warning", "Zip File IsNull Or Empty") Return -1 End If Try //Create Oleobject oZipShell = Create OleObject li_rc = oZipShell.ConnectToNewObject ( "Shell.Application") If li_rc < 0 Then MessageBox("Warning", "ConnectToNewObject Shell.Application") Destroy oZipShell Return -1 End If oZipFSO = Create OleObject li_rc = oZipFSO.ConnectToNewObject ("Scripting.FileSystemObject" ) If li_rc < 0 Then MessageBox("Warning", "ConnectToNewObject Scripting.FileSystemObject") Destroy oZipFSO Return -1 End If //That zip file already exists - deleting it. If oZipFSO.FileExists(ls_ZipFile) And Not ab_append Then oZipFSO.DeleteFile (ls_ZipFile) End If //Create File If Not oZipFSO.FileExists(ls_ZipFile) Then oNewZipFile = Create OleObject oNewZipFile = oZipFSO.CreateTextFile(ls_ZipFile) oNewZipFile.Close End If //Add File oZip = oZipShell.NameSpace(ls_ZipFile) ll_ZipFileCount = oZip.Items.Count oZip.Copyhere( ls_File, 4) //Keep script waiting until Compressing is done Do While ll_ZipFileCount >= oZip.Items.Count SleepMS(500) Loop Catch (runtimeerror e) String ls_msg ls_msg = e.getMessage() MessageBox("Warning", ls_msg) Destroy oZipShell Destroy oZipFSO Destroy oNewZipFile Destroy oZip Return -1 End Try Destroy oZipShell Destroy oZipFSO Destroy oNewZipFile Destroy oZip Return 0 end function public function integer of_addzip (string as_file, string as_zipfile);Return of_addzip(as_file, as_zipfile, False) end function on nvo_winzip.create call super::create TriggerEvent( this, "constructor" ) end on on nvo_winzip.destroy TriggerEvent( this, "destructor" ) call super::destroy end on |
Create Windown Example: w_main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
forward global type w_main from window end type type st_3 from statictext within w_main end type type st_2 from statictext within w_main end type type st_1 from statictext within w_main end type type sle_des from singlelineedit within w_main end type type sle_sc from singlelineedit within w_main end type type cb_unzip from commandbutton within w_main end type type cb_zipfolder from commandbutton within w_main end type type cb_zipfile from commandbutton within w_main end type end forward global type w_main from window integer width = 2496 integer height = 740 boolean titlebar = true string title = "PB Window Zip" boolean controlmenu = true boolean minbox = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true st_3 st_3 st_2 st_2 st_1 st_1 sle_des sle_des sle_sc sle_sc cb_unzip cb_unzip cb_zipfolder cb_zipfolder cb_zipfile cb_zipfile end type global w_main w_main on w_main.create this.st_3=create st_3 this.st_2=create st_2 this.st_1=create st_1 this.sle_des=create sle_des this.sle_sc=create sle_sc this.cb_unzip=create cb_unzip this.cb_zipfolder=create cb_zipfolder this.cb_zipfile=create cb_zipfile this.Control[]={this.st_3,& this.st_2,& this.st_1,& this.sle_des,& this.sle_sc,& this.cb_unzip,& this.cb_zipfolder,& this.cb_zipfile} end on on w_main.destroy destroy(this.st_3) destroy(this.st_2) destroy(this.st_1) destroy(this.sle_des) destroy(this.sle_sc) destroy(this.cb_unzip) destroy(this.cb_zipfolder) destroy(this.cb_zipfile) end on type st_3 from statictext within w_main integer y = 32 integer width = 2450 integer height = 128 integer textsize = -20 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Window Zip" alignment alignment = center! boolean focusrectangle = false end type type st_2 from statictext within w_main integer x = 37 integer y = 384 integer width = 325 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Destination:" alignment alignment = right! boolean focusrectangle = false end type type st_1 from statictext within w_main integer x = 37 integer y = 256 integer width = 325 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Source:" alignment alignment = right! boolean focusrectangle = false end type type sle_des from singlelineedit within w_main integer x = 366 integer y = 368 integer width = 2011 integer height = 92 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type sle_sc from singlelineedit within w_main integer x = 366 integer y = 244 integer width = 2011 integer height = 92 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type cb_unzip from commandbutton within w_main integer x = 2011 integer y = 520 integer width = 370 integer height = 96 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "UnZip" end type event clicked;String ls_sc, ls_des ls_sc = sle_sc.Text ls_des = sle_des.Text If IsNull(ls_sc) Or Len(Trim(ls_sc)) = 0 Then MessageBox("Warning", "File Zip IsNull") sle_sc.setfocus( ) Return End If If IsNull(ls_des) Or Len(Trim(ls_des)) = 0 Then MessageBox("Warning", "Folder UnZip Destination IsNull") sle_des.setfocus( ) Return End If If Not FileExists(ls_sc) Then MessageBox("Warning", "File Zip Not Exists") sle_sc.setfocus( ) Return End If nvo_winzip lnvo_winzip lnvo_winzip.of_unzip( ls_sc, ls_des) end event type cb_zipfolder from commandbutton within w_main integer x = 1207 integer y = 520 integer width = 370 integer height = 96 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Zip Folder" end type event clicked;String ls_sc, ls_des ls_sc = sle_sc.Text ls_des = sle_des.Text If IsNull(ls_sc) Or Len(Trim(ls_sc)) = 0 Then MessageBox("Warning", "Folder Source IsNull") sle_sc.setfocus( ) Return End If If IsNull(ls_des) Or Len(Trim(ls_des)) = 0 Then MessageBox("Warning", "File Zip IsNull") sle_des.setfocus( ) Return End If If Not DirectoryExists(ls_sc) Then MessageBox("Warning", "Folder Source Not Exists") sle_sc.setfocus( ) Return End If nvo_winzip lnvo_winzip lnvo_winzip.of_addfolderzip( ls_sc,ls_des) end event type cb_zipfile from commandbutton within w_main integer x = 366 integer y = 520 integer width = 370 integer height = 96 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Zip File" end type event clicked; String ls_sc, ls_des ls_sc = sle_sc.Text ls_des = sle_des.Text If IsNull(ls_sc) Or Len(Trim(ls_sc)) = 0 Then MessageBox("Warning", "File To Zip IsNull") sle_sc.setfocus( ) Return End If If IsNull(ls_des) Or Len(Trim(ls_des)) = 0 Then MessageBox("Warning", "File Zip IsNull") sle_des.setfocus( ) Return End If If Not FileExists(ls_sc) Then MessageBox("Warning", "File Source Not Exists") sle_sc.setfocus( ) Return End If nvo_winzip lnvo_winzip lnvo_winzip.of_addzip( ls_sc, ls_des) end event |
Find Projects On Github click here
Good Luck!
Subscribe
Login
0 Comments