Imports System.IO
Imports System.Text
Imports System.Threading
Module Module1
Sub Main()
'Print_Document("C:\0930308.PDF")
Dir_Watch()
End Sub
Private Sub Print_Document(ByVal strDocpath As String)
Dim p As New Process
p.StartInfo.FileName = strDocpath
p.StartInfo.Verb = "print"
p.StartInfo.CreateNoWindow = True
p.Start()
End Sub
Public Sub Dir_Watch()
Dim watcher As New FileSystemWatcher()
'Dim Watch_Path As String = "C:\WATCH"
watcher.Path = "C:\WATCH"
If Not IO.Directory.Exists(watcher.Path) Then
IO.Directory.CreateDirectory(watcher.Path)
End If
watcher.Filter = "*.pdf"
watcher.IncludeSubdirectories = False
AddHandler watcher.Created, AddressOf doIt
watcher.EnableRaisingEvents = True
Dim msg As String = "Printapplication 1.01 @C ..." & vbLf & _
vbLf & "PDF Datei in das Verzeichnis C:\WATCHER kopieren" & vbLf & _
"Datei wird dann auf dem Windows Standarddrucker gedruckt und anschl. umbenannt" & vbLf & _
vbLf & "mit Taste das Programm beenden " & vbLf
Console.WriteLine(msg)
Console.ReadLine()
End Sub
Sub doit(ByVal source As Object, ByVal e As FileSystemEventArgs)
Print_Document(e.FullPath)
If IO.File.Exists(e.FullPath) Then
Dim newfile As String = RandomString(8, False) & ".PRINTED"
Dim newfile_fullpath As String = "c:\watcher\" & newfile ' & ".PRINTED"
'IO.File.Move(e.FullPath, "c:\watcher\" & newfile_fullpath)
Dim fi As New FileInfo(e.FullPath)
Threading.Thread.Sleep(10000)
fi.MoveTo("C:\WATCH\" & newfile)
End If
End Sub
Private Function RandomString(ByVal size As Integer, ByVal lowerCase As Boolean) As String
Dim builder As New StringBuilder()
Dim random As New Random()
Dim ch As Char
Dim i As Integer
For i = 0 To size - 1
ch = Convert.ToChar(Convert.ToInt32((26 * random.NextDouble() + 65)))
builder.Append(ch)
Next
If lowerCase Then
Return builder.ToString().ToLower()
End If
Return builder.ToString()
End Function 'RandomString
End Module
|