知道路径,从计算机中删除特定文件

时间:2015-02-02 19:15:37

标签: vb.net file timer path delete-file

我正在使用计时器在一段时间后拍摄屏幕截图并将图像保存到特定路径。

Private Sub tmrPS1_Tick(sender As Object, e As EventArgs) Handles tmrPS1.Tick
    Dim bounds As Rectangle
    Dim screenshot As System.Drawing.Bitmap
    Dim graph As Graphics
    bounds = Screen.PrimaryScreen.Bounds
    screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    graph = Graphics.FromImage(screenshot)
    graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
    PictureBox1.Image = screenshot
    PictureBox1.Image.Save("C:\ImagesFolder\1.jpg")
    tmrPS1.Enabled = False
End Sub

我想要另一个计时器在我发送邮件之后将其删除,因为我将不得不采取新的计时器。我的问题是如何删除知道路径的图像?

1 个答案:

答案 0 :(得分:1)

完成后删除/重新创建文件夹?

        If IO.Directory.Exists(DestinationFolder) Then IO.Directory.Delete(DestinationFolder, True)
        Application.DoEvents()
        IO.Directory.CreateDirectory(DestinationFolder)

此代码使用与我正在保存的文件相同的扩展名清除“Temp”中的文件。

                With My.Computer.FileSystem
                    Dim s As String = Environ("temp")
                    For Each foundFile As String In .GetFiles(s, FileIO.SearchOption.SearchTopLevelOnly, "*.tmp.kml")
                        .DeleteFile(foundFile) ' clean up old output
                    Next
               End With