Advertisement
rg443

aspZip.class.asp

Sep 1st, 2015
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <%
  2. ' Classic ASP CSV creator 0.3
  3.  
  4. class aspZip
  5.     dim BlankZip, NoInterfaceYesToAll
  6.     dim fso, curArquieve, created, saved
  7.     dim files, m_path, zipApp, zipFile 
  8.    
  9.     public property get Count()
  10.         Count = files.Count
  11.     end property
  12.    
  13.     public property get Path
  14.         Path = m_path
  15.     end property
  16.    
  17.    
  18.     private sub class_initialize()
  19.         BlankZip = Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)  ' Create the blank file structure
  20.         NoInterfaceYesToAll = 4 or 16 or 1024 ' http://msdn.microsoft.com/en-us/library/windows/desktop/bb787866(v=vs.85).aspx
  21.        
  22.         ' initialize components
  23.         set fso = createObject("scripting.filesystemobject")
  24.         set files = createObject("Scripting.Dictionary")
  25.        
  26.         Set zipApp = CreateObject("Shell.Application")
  27.     end sub
  28.    
  29.     private sub class_terminate()
  30.         ' some cleanup
  31.         set curArquieve = nothing
  32.         set zipApp = nothing
  33.         set files = nothing
  34.        
  35.         ' If we created the file but did not saved it, delete it
  36.         ' since its empty
  37.         if created and not saved then
  38.             on error resume next
  39.             fso.deleteFile m_path
  40.             on error goto 0
  41.         end if
  42.        
  43.         set fso = nothing
  44.     end sub
  45.    
  46.    
  47.     ' Opens or creates the arquieve
  48.     public sub OpenArquieve(byval path)
  49.         dim file
  50.         ' Make sure the path is complete and in a correct format
  51.         path = replace(path, "/", "\")
  52.         m_path = Server.MapPath(path)
  53.        
  54.         ' Create an empty file if it already doesn't exists
  55.         if not fso.fileexists(m_path) then
  56.             set file = fso.createTextFile(m_path)
  57.             file.write BlankZip
  58.             file.close()
  59.             set file = nothing
  60.            
  61.             set curArquieve = zipApp.NameSpace(m_path)
  62.             created = true
  63.         else
  64.             ' Open the existing file and load its contents
  65.            
  66.             dim cnt
  67.             set curArquieve = zipApp.NameSpace(m_path)
  68.            
  69.             cnt = 0
  70.             for each file in curArquieve.Items
  71.                 cnt = cnt + 1
  72.                 files.add file.path, cnt
  73.             next
  74.         end if
  75.  
  76.         saved = false
  77.     end sub
  78.    
  79.    
  80.     ' Add a file or folder to the list
  81.     public sub Add(byval path)
  82.         path = replace(path, "/", "\")     
  83.         if instr(path, ":") = 0 then path = Server.mappath(path)
  84.        
  85.         if not fso.fileExists(path) and not fso.folderExists(path) then
  86.             err.raise 1, "File not exists", "The input file name doen't correspond to an existing file"
  87.            
  88.         elseif not files.exists(path) Then
  89.             files.add path, files.Count + 1
  90.         end if
  91.     end sub
  92.    
  93.     ' Remove a file or folder from the to be added list (currently it only works for new files)
  94.     public sub Remove(byval path)
  95.         if files.exists(path) then files.Remove(path)
  96.     end sub
  97.    
  98.     ' Clear the to be added list
  99.     public sub RemoveAll()
  100.         files.RemoveAll()
  101.     end sub
  102.    
  103.     ' Writes the to the arquieve
  104.     public sub CloseArquieve()
  105.         dim filepath, file, initTime, fileCount
  106.         dim cnt
  107.         cnt = 0
  108.  
  109.         For Each filepath In files.keys
  110.             ' do not try add the contents that are already in the arquieve
  111.             if instr(filepath, m_path) = 0 then
  112.                 curArquieve.Copyhere filepath, NoInterfaceYesToAll
  113.                 fileCount = curArquieve.items.Count
  114.                
  115.                 'Keep script waiting until Compressing is done
  116.                 On Error Resume Next
  117.                 'Do Until fileCount < curArquieve.Items.Count
  118.                     wscript.sleep(10)
  119.                     cn = cnt + 1
  120.                 'Loop
  121.                 On Error GoTo 0
  122.             end if
  123.         next
  124.        
  125.         saved = true
  126.     end sub
  127.    
  128.    
  129.     public sub ExtractTo(byval path)
  130.         if typeName(curArquieve) = "Folder3" Then
  131.             path = Server.MapPath(path)
  132.            
  133.             if not fso.folderExists(path) then
  134.                 fso.createFolder(path)
  135.             end if
  136.            
  137.             zipApp.NameSpace(path).CopyHere curArquieve.Items, NoInterfaceYesToAll
  138.         end if
  139.     end sub
  140. end class
  141. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement