• Viernes 19 de Abril de 2024, 23:36

Autor Tema:  Archivos .ini  (Leído 1083 veces)

akira

  • Nuevo Miembro
  • *
  • Mensajes: 15
    • Ver Perfil
Archivos .ini
« en: Martes 29 de Marzo de 2005, 16:43 »
0
Hola amigos/as tengo una pregunta para ud's, tengo un programa que logea cambios de archivos en un directorio, lo que me gustaria hacer, es que lea un archivo ini en el cual le pueda definir todas las variables para que verifique archivos o directorios, se que esto va a ser mas complicado, pero me gustaria que me den una mano.
Saludos.
Adjunto mi programa.
[CODE]Option Explicit On
Option Strict Off
Imports System
Imports System.IO
Imports System.Diagnostics
Imports Microsoft.VisualBasic

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Código generado por el Diseñador de Windows Forms "

    Public Sub New()
        MyBase.New()

        'El Diseñador de Windows Forms requiere esta llamada.
        InitializeComponent()

        'Agregar cualquier inicialización después de la llamada a InitializeComponent()

    End Sub

    'Form reemplaza a Dispose para limpiar la lista de componentes.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Requerido por el Diseñador de Windows Forms
    Private components As System.ComponentModel.IContainer

    'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
    'Puede modificarse utilizando el Diseñador de Windows Forms.
    'No lo modifique con el editor de código.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txt_watchpath As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents btn_startwatch As System.Windows.Forms.Button
    Friend WithEvents btn_stop As System.Windows.Forms.Button
    Friend WithEvents txt_folderactivity As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.txt_watchpath = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.btn_startwatch = New System.Windows.Forms.Button
        Me.btn_stop = New System.Windows.Forms.Button
        Me.txt_folderactivity = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 40)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(152, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Ingresar Carpeta a Scannear"
        '
        'txt_watchpath
        '
        Me.txt_watchpath.Location = New System.Drawing.Point(160, 40)
        Me.txt_watchpath.Name = "txt_watchpath"
        Me.txt_watchpath.Size = New System.Drawing.Size(248, 20)
        Me.txt_watchpath.TabIndex = 1
        Me.txt_watchpath.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(24, 112)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(120, 16)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Actividad en la carpeta"
        '
        'btn_startwatch
        '
        Me.btn_startwatch.Location = New System.Drawing.Point(440, 40)
        Me.btn_startwatch.Name = "btn_startwatch"
        Me.btn_startwatch.Size = New System.Drawing.Size(120, 24)
        Me.btn_startwatch.TabIndex = 3
        Me.btn_startwatch.Text = "Empezar"
        '
        'btn_stop
        '
        Me.btn_stop.Location = New System.Drawing.Point(440, 80)
        Me.btn_stop.Name = "btn_stop"
        Me.btn_stop.Size = New System.Drawing.Size(120, 24)
        Me.btn_stop.TabIndex = 4
        Me.btn_stop.Text = "Detener"
        '
        'txt_folderactivity
        '
        Me.txt_folderactivity.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txt_folderactivity.AutoSize = False
        Me.txt_folderactivity.Location = New System.Drawing.Point(24, 136)
        Me.txt_folderactivity.Name = "txt_folderactivity"
        Me.txt_folderactivity.Size = New System.Drawing.Size(552, 216)
        Me.txt_folderactivity.TabIndex = 5
        Me.txt_folderactivity.Text = ""
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(592, 365)
        Me.Controls.Add(Me.txt_folderactivity)
        Me.Controls.Add(Me.btn_stop)
        Me.Controls.Add(Me.btn_startwatch)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txt_watchpath)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Form1"
        Me.Text = "File Logger"
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txt_folderactivity.Multiline = True
        txt_folderactivity.ScrollBars = ScrollBars.Vertical
    End Sub
    Public watchfolder As FileSystemWatcher
    Private Sub btn_startwatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_startwatch.Click
        watchfolder = New System.IO.FileSystemWatcher
        watchfolder.Path = txt_watchpath.Text
        watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
        watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
                                   IO.NotifyFilters.FileName
        watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
                                   IO.NotifyFilters.Attributes

        AddHandler watchfolder.Created, AddressOf logchange
        AddHandler watchfolder.Deleted, AddressOf logchange
        AddHandler watchfolder.Renamed, AddressOf logrename
        watchfolder.EnableRaisingEvents = True

        btn_startwatch.Enabled = False
        btn_stop.Enabled = True
    End Sub
    Private Sub logchange(ByVal source As Object, ByVal e As _
                            System.IO.FileSystemEventArgs)
        Dim sr As StreamWriter
        Dim f As String = e.FullPath
        Dim arc As New System.IO.FileInfo(f)
        Dim dt As DateTime = DateTime.Now
        Const FILE_NAME As String = "C:\logbckp.txt"
        If File.Exists(FILE_NAME) = True Then
            sr = File.AppendText(FILE_NAME)
            If e.ChangeType = IO.WatcherChangeTypes.Created Then
                sr.WriteLine("El archivo  " & e.FullPath & _
                                         " ha sido creado" & vbCrLf)
                txt_folderactivity.Text &= "El archivo  " & e.FullPath & _
                                         " ha sido creado" & vbCrLf
                sr.WriteLine("Tamaño archivo en bytes " & arc.Length & _
                            "Fecha de modificacion " & dt.ToString("d") & vbCrLf)
                txt_folderactivity.Text &= "Tamaño archivo en bytes " & arc.Length & _
                            " fecha modificacion " & dt.ToString("d") & vbCrLf
            End If
            If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
                sr.WriteLine("El archivo " & e.FullPath & _
                                        " ha sido borrado" & vbNewLine)
                txt_folderactivity.Text &= "El archivo " & e.FullPath & _
                                        " ha sido borrado" & vbNewLine
                txt_folderactivity.Text &= " fecha eliminacion " & _
                dt.ToString("d") & vbNewLine
            End If
            sr.Flush()
            sr.Close()
        End If

        If File.Exists(FILE_NAME) = False Then
            sr = File.CreateText(FILE_NAME)
            If e.ChangeType = IO.WatcherChangeTypes.Created Then
                sr.WriteLine("El archivo  " & e.FullPath & _
                                         " ha sido creado" & vbCrLf)
                txt_folderactivity.Text &= "El archivo  " & e.FullPath & _
                                         " ha sido creado" & vbCrLf
                txt_folderactivity.Text &= "Tamaño archivo en bytes " & arc.Length & _
                " fecha modificacion " & dt.ToString("d") & vbCrLf
            End If
            If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
                sr.WriteLine("El archivo " & e.FullPath & _
                                        " ha sido borrado" & vbCrLf)
                txt_folderactivity.Text &= "El archivo " & e.FullPath & _
                                        " ha sido borrado" & vbCrLf
                txt_folderactivity.Text &= "Tamaño archivo en bytes " & arc.Length & _
                " fecha modificacion " & dt.ToString("d") & vbCrLf
            End If
            sr.WriteLine("Tamaño archivo en bytes " & arc.Length & _
            " fecha modificacion " & dt.ToString("d") & vbCrLf)
            sr.Flush()
            sr.Close()
        End If

    End Sub
    Public Sub logrename(ByVal source As Object, ByVal e As _
                                System.IO.RenamedEventArgs)
        Const FILE_NAME As String = "C:\logbckp.txt"
        Dim sr As StreamWriter
        Dim f As String = e.FullPath
        Dim arc As New System.IO.FileInfo(f)
        Dim dt As DateTime = DateTime.Now
        If File.Exists(FILE_NAME) = True Then
            sr = File.AppendText(FILE_NAME)
            sr.WriteLine("El Archivo " & e.OldName & _
            " ha sido renombrado a  " & e.Name & vbCrLf)
            sr.WriteLine(" tamaño archivo en bytes " & arc.Length & _
           " fecha modificacion " & dt.ToString("d") & vbCrLf)
            sr.Flush()
            sr.Close()
            txt_folderactivity.Text &= "El Archivo " & e.OldName & _
            " ha sido renombrado a  " & e.Name & vbCrLf
            txt_folderactivity.Text &= "Tamaño archivo en bytes " & arc.Length & _
            " fecha modificacion " & dt.ToString("d") & vbCrLf
        End If
        If File.Exists(FILE_NAME) = False Then
            sr = File.CreateText(FILE_NAME)
            sr.WriteLine("El Archivo " & e.OldName & _
            " ha sido renombrado a  " & e.Name & vbCrLf)
            sr.WriteLine("Tamaño archivo en bytes " & arc.Length & _
            " fecha modificacion " & dt.ToString("d") & vbCrLf)
            sr.Flush()
            sr.Close()
            txt_folderactivity.Text &= "El Archivo " & e.OldName & _
            " ha sido renombrado a  " & e.Name & vbCrLf
            txt_folderactivity.Text &= " tamaño archivo en bytes " & arc.Length & _
                           " fecha modificacion " & dt.ToString("d") & vbCrLf
        End If
    End Sub

    Private Sub btn_stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_stop.Click
        watchfolder.EnableRaisingEvents = False
        btn_startwatch.Enabled = True
        btn_stop.Enabled = False
    End Sub

    Private Sub txt_watchpath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_watchpath.TextChanged

    End Sub

    Private Sub txt_folderactivity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub txt_folderactivity_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_folderactivity.TextChanged

    End Sub
End Class



 :lightsabre: