16,554
社区成员
发帖
与我相关
我的任务
分享
private sub delete_jpg()
Dim file_open As New FolderBrowserDialog '定义路径选择
Dim Path_temp As String
Dim filenames() As String '数组存储文件名
If file_open.ShowDialog <> DialogResult.OK Then
Exit Sub
End If
Try
Path_temp = file_open.SelectedPath '获取选择的路径字符串
filenames = GetFiles(Path_temp, "*.jpg") '获取路径下jpg格式的文件
For i = 0 To filenames.Length - 1
My.Computer.FileSystem.DeleteFile(filenames(i))
Next
MsgBox("Mission Complete!")
Catch ex As Exception
MsgBox("Mission Failed!" & ex.Message) '捕捉错误信息
End Try
End sub
public void Deleteflie(string path)
{
if (Directory.GetFileSystemEntries(path).Length > 0)
{
//遍历文件夹中所有文件
foreach (string file in Directory.GetFiles(path))
{
//文件己存在
if (System.IO.File.Exists(file))
{
FileInfo fi = new FileInfo(file);
//判断当前文件属性是否是只读
if (fi.Attributes.ToString().IndexOf("ReadyOnly") >= 0)
{
fi.Attributes = FileAttributes.Normal;
}
//删除文件
System.IO.File.Delete(file);
}
}
//删除文件夹
Directory.Delete(path);
}
}
DEL /F /S /Q %1\*.jpg
批处理就行啊