我有文件夹D:\both_img
。在该文件夹中,我有大量可读和不可读的.bmp
图像。
如何将不可读的图像移动到另一个文件夹?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim openfiled1 As New OpenFileDialog
If openfiled1.ShowDialog <> DialogResult.Cancel Then
PictureBox1.Image = Image.FromFile(openfiled1.FileName)
End If
End Sub
答案 0 :(得分:2)
请尝试以下代码:
Dim di As New DirectoryInfo("D:\both_img")
Dim fiArr As FileInfo() = di.GetFiles()
Dim fi As FileInfo
For Each fi In fiArr
Try
Dim image1 As Bitmap = CType(Image.FromFile(fi.FullName, True), Bitmap)
fi.MoveTo(validFiledestPath) 'Move to valid file folder
Catch ex As OutOfMemoryException
fi.MoveTo(invalidFileDestPath) 'Move to invalid file folder
End Try
Next fri
此代码迭代所有文件。尝试使用Image.FromFile
打开它们,如果打开则将它们移动到有效文件夹,否则移动到无效文件夹
References