• Viernes 29 de Marzo de 2024, 12:23

Autor Tema:  Pregunta, Modificacion Archivos  (Leído 3349 veces)

akira

  • Nuevo Miembro
  • *
  • Mensajes: 15
    • Ver Perfil
Pregunta, Modificacion Archivos
« en: Lunes 21 de Marzo de 2005, 18:41 »
0
Hola que tal soy nuevo en VB .NET, me han pedido que haga un aplicativo que chequee la fecha de un archivo para saber si ha sido modificado, cualquier ayuda sobre el tema es apreciado, ya que no tengo idea ni por donde empezar.
Saludos

Güorker

  • Miembro MUY activo
  • ***
  • Mensajes: 383
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #1 en: Martes 22 de Marzo de 2005, 08:12 »
0
Hola,

podrías utilizar la clase FileInfo. Para mas información visita la ayuda online de la MSDN.

saludos
[size=109]Ondo ibili, gutxi gastau eta bueltak amari[/size]
[size=109]Pasalo bien, gasta poco y las vueltas a tu madre[/size]

akira

  • Nuevo Miembro
  • *
  • Mensajes: 15
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #2 en: Martes 22 de Marzo de 2005, 18:34 »
0
Ok, gracias tengo entendido que la clase fileinfo es para administrar archivos (copiar, modificar, etc), lo que necesito yo es verificar la fecha y en caso de que haya sido modificada que me de un aviso.
Lo que necesitaria es si alguien me puede pasar algun codigo comoo para analizarlo y tener una idea un poco mas acabada del tema.
Saludos.
Gracias por la respuesta..
Cualquier ayuda se agradece

Güorker

  • Miembro MUY activo
  • ***
  • Mensajes: 383
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #3 en: Miércoles 23 de Marzo de 2005, 08:30 »
0
Hola de nuevo,

Yo no es que haya utilizado mucho la clase FileInfo, pero creo que es perfectamente valido para lo que tu pretendes.

No se si te habras molestado en mirar un poco esta clase, pero con los metodos CreationTime y LastAccessTime o LastWriteTime estoy seguro de que se puede saber si alguien lo ha modificado desde que se creó el archivo.

Por ejemplo: CreationTime < LastWriteTime --> Modificado

Si lo que realmente pretendes es que alguien te mande un programa completo que haga lo que tu quieres, te dire dos cosas:
- Los foros tratan de estimular los conocimientos y la creatividad y no de hacer el trabajo de los demas
- Por muy bueno que sea el programa seguro que no hace todo lo que tu quieres o hay algo que no lo hace a tu gusto.

Permiteme un consejo, experimenta y no esperes a que te den las cosas hechas.

Saludos.
[size=109]Ondo ibili, gutxi gastau eta bueltak amari[/size]
[size=109]Pasalo bien, gasta poco y las vueltas a tu madre[/size]

akira

  • Nuevo Miembro
  • *
  • Mensajes: 15
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #4 en: Miércoles 23 de Marzo de 2005, 13:56 »
0
Estamos 100% de acuerdo, yo por lo que habia leido en MSDN de esa clase no vi o por lo menos no mostraban esas dos funcionalidades que tan amablemente me comentaste.
No pretendo que nadie me mande un programa terminado que haga algo similar a lo que quiero, pero si pretendo que en la medida de lo posible me manden algun programita basico como para ver como funciona el visual basic .net ya que estoy leyendo el manual pero esta largo y nos se si terminare de leerlo.
Como te dije antes  muchas gracias por tu respuesta y vere como hago esto.
Saludos.
 :hola:

Güorker

  • Miembro MUY activo
  • ***
  • Mensajes: 383
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #5 en: Miércoles 23 de Marzo de 2005, 14:58 »
0
No hay nada que agradecer.

Te deseo suerte en tu proceso de aprendizaje, y te animo a que mantengas una constancia e iniciativa.

Saludos
[size=109]Ondo ibili, gutxi gastau eta bueltak amari[/size]
[size=109]Pasalo bien, gasta poco y las vueltas a tu madre[/size]

akira

  • Nuevo Miembro
  • *
  • Mensajes: 15
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #6 en: Viernes 25 de Marzo de 2005, 07:28 »
0
Lo logre pude hacer una parte del codigo, el lunes voy a hacer el post, pero aun asi me quedan un par de dudas que me gustaria aclarar.
SAludos.

akira

  • Nuevo Miembro
  • *
  • Mensajes: 15
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #7 en: Martes 29 de Marzo de 2005, 15:46 »
0
Tengo el siguiente problema, en el text box no me imprime los avisos uno abajo del otro.
[/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

        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
            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
            End If
            sr.WriteLine("tamaño archivo en bytes" & arc.Length & _
            " fecha de modificacion " & dt.ToString("d") & vbCrLf)
            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
            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
            End If
            sr.WriteLine(" tamaño archivo en bytes" & arc.Length & _
            " fecha modificacion " & dt.ToString("d") & vbCrLf)
            sr.Flush()
            sr.Close()
        End If
        txt_folderactivity.Text &= " tamaño archivo en bytes" & arc.Length & _
         " fecha modificacion " & dt.ToString("d") & vbCrLf
    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

[CODE]

Güorker

  • Miembro MUY activo
  • ***
  • Mensajes: 383
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #8 en: Miércoles 30 de Marzo de 2005, 11:33 »
0
Mira,

me gustaria ayudarte, pero con ese pedazo trozo de codigo no me aclaro.

Si puedes pon solo el trozo de codigo que te de problemas y a poder ser marca con colores, subrayado, ... la línea que crres que te da el problema.

Porque si no, yo ya tengo suficientes fuentes para prederme en ellos como para andar perdiendome en el de los demas.


Saludos
[size=109]Ondo ibili, gutxi gastau eta bueltak amari[/size]
[size=109]Pasalo bien, gasta poco y las vueltas a tu madre[/size]

akira

  • Nuevo Miembro
  • *
  • Mensajes: 15
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #9 en: Viernes 1 de Abril de 2005, 18:11 »
0
Gracias por la respuesta lo que necesitaria hacer es cargar mas de un directorio en el tipo filesystemwatcher.path, osea que me vea los eventos en mas de un direcotio, ej. C:\TEMP y C:\PRUEBA, como hago esto?
Desde ya muchas gracias.
Saludos, aca paso el codigo donde defino eso.
Código: Text
  1.  
  2.  watchfolder = New System.IO.FileSystemWatcher
  3.  
  4.         watchfolder.Path = txt_watchpath.Text
  5.         watchfolder.IncludeSubdirectories = True
  6.         watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
  7.         watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
  8.                                    IO.NotifyFilters.FileName
  9.         watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
  10.                                    IO.NotifyFilters.Attributes
  11.  
  12.  
txt_watchpath.text lo reeemplazaria por los directorios que necesito poner, eliminando la entrada de directorios manualmente.
Gracias.

Güorker

  • Miembro MUY activo
  • ***
  • Mensajes: 383
    • Ver Perfil
Re: Pregunta, Modificacion Archivos
« Respuesta #10 en: Lunes 4 de Abril de 2005, 08:29 »
0
Hola,

Lo unico que se me ocurre para hacer lo que quieres es tener 2 objetos FileSystemWatcher.

Bueno, suerte con tus investigaciones
[size=109]Ondo ibili, gutxi gastau eta bueltak amari[/size]
[size=109]Pasalo bien, gasta poco y las vueltas a tu madre[/size]