Untitled
unknown
vbscript
3 years ago
2.6 kB
7
Indexable
Option Explicit
Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChange As Long) As Long
Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChange As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
Private Const INFINITE = &HFFFFFFFF
Private hChange As Long ' Declarar la variable a nivel de formulario
Private Sub Form_Load()
Dim dirName As String
dirName = "C:\logs"
hChange = FindFirstChangeNotification(dirName, False, FILE_NOTIFY_CHANGE_FILE_NAME)
If hChange = 0 Then
MsgBox "Error: No se pudo establecer la notificación de cambios en la carpeta.", vbCritical
Exit Sub
End If
End Sub
Private Sub tmrMonitorizar_Timer()
MonitorizarCarpeta
End Sub
Private Sub MonitorizarCarpeta()
Dim res As Long
Dim dirName As String
dirName = "C:\logs"
res = WaitForSingleObject(hChange, 0)
If res = 0 Then
' Un nuevo archivo ha sido creado en la carpeta
Dim fileName As String
Dim fso As New Scripting.FileSystemObject
Dim content As String
Dim file As Scripting.TextStream
fileName = Dir(dirName & "\*.log")
If fileName <> "" Then
fileName = dirName & "\" & fileName ' Construir el nombre completo del archivo
Set file = fso.OpenTextFile(fileName, ForReading)
content = file.ReadAll
file.Close
' Enviar el contenido del archivo al bot de Discord
Dim url As String
Dim http As New WinHttp.WinHttpRequest
url = "http://localhost:3000/api/logs/" & Mid(fileName, InStrRev(fileName, "\") + 1) ' Reemplazar con la URL de tu bot
http.Open "POST", url, False
http.setRequestHeader "Content-Type", "text/plain"
http.send content ' Enviar el contenido del archivo en el cuerpo de la solicitud
Debug.Print url
Debug.Print "Contenido: " & content
End If
FindNextChangeNotification hChange ' Esperar al siguiente cambio en la carpeta
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If hChange <> 0 Then
FindCloseChangeNotification hChange
End If
End SubEditor is loading...