Imports System.Data Imports System.Configuration Imports System.Collections Imports System.Collections.Specialized Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.IO Imports System.Text Imports GetData Public Partial Class Default2 Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object,e As EventArgs) Dim folder As String = Server.MapPath("upload") GetAllFiles(folder) End Sub ''' <summary> ''' 作为遍历文件函数的子函数 ''' </summary> ''' <param name="parentDir">目录名称</param> ''' <param name="result">该目录下的所有文件</param> Public Sub GetAllFiles(parentDir As String) '获取目录parentDir下的所有的子文件夹 Dim dir As String() = Directory.GetDirectories(parentDir) For i As Integer = 0 To dir.Length - 1 GetAllFiles(dir(i)) Next '获取目录parentDir下的所有的文件,并过滤得到所有的文本文件 Dim file As String() = Directory.GetFiles(parentDir) For i As Integer = 0 To file.Length - 1 Dim fi As New FileInfo(file(i)) If fi.Extension.ToLower() = ".jpg" OrElse fi.Extension.ToLower() = ".bmp" Then Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(fi.FullName,i.ToString() & ".jpg") End If Next Response.Write("<br />") End Sub End Class
www.jiangnuodr.cn