Sub Page_Load()
Dim RootPath As String
RootPath = "e:\Lynn\site\working"
If IsPostBack = False Then
GetPath(RootPath)
End If
End Sub Public Sub GetPath(ByVal RootPath As String)
' Dim di As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(path)
Dim di = New System.IO.DirectoryInfo(RootPath)
Dim subDirs As System.IO.DirectoryInfo() = di.GetDirectories()
Dim i As Integer = 0
While i < subDirs.Length
Dim Dirname As String
dirname = subDirs(i).Name
If Dirname <> "_vti_cnf" Then
Response.Write(RootPath + "\" + Dirname + "\" + "<br>")
GetPath(RootPath + "\" + Dirname)
End If
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
End While
Dim files As System.IO.FileInfo() = di.GetFiles()
Dim j As Integer = 0
While j < files.Length
Dim Filename As String
Dim FileModiTime As String
Filename = files(j).Name
FileModiTime = files(j).LastAccessTime
Response.Write(files(j).Name + " " + files(j).LastAccessTime + "<br>")
System.Math.Max(System.Threading.Interlocked.Increment(j), j - 1)
End While End Sub
得到了e:\Lynn\site\working文件夹下的子目录。以及子目录下的文件名及最后修改时间了。
但是有一个目录显示有点问题,这2个目录连在一起显示出来了。
e:\Lynn\site\working\Reporting\
e:\Lynn\site\working\Reporting\Report\
文件名 最后修改时间
文件名 最后修改时间
文件名 最后修改时间
......正确的格式
e:\Lynn\site\working\Reporting\
文件名 最后修改时间
......
e:\Lynn\site\working\Reporting\Report\
文件名 最后修改时间
文件名 最后修改时间
文件名 最后修改时间
......因为只有Reporting还有个子文件夹。其他的都能正常显示。还有一个问题就是e:\Lynn\site\working\这个我要查询的根目录下的文件。这个根目录不显示了。
就直接跟着之前的文件“文件名 最后修改时间 ”直接显示在下面了。应该是文件名 最后修改时间
......
e:\Lynn\site\working\
文件名 最后修改时间
文件名 最后修改时间
......
Public Sub GetPath(ByVal RootPath As String)
' Dim di As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(path)
Dim di = New System.IO.DirectoryInfo(RootPath)
Dim subDirs As System.IO.DirectoryInfo() = di.GetDirectories()
Dim i As Integer = 0
While i < subDirs.Length
Dim Dirname As String
dirname = subDirs(i).Name
If Dirname <> "_vti_cnf" Then
Response.Write(RootPath + "\" + Dirname + "\" + "<br>")
'这里写输出的文件名称 日期等信息(可以改下面的
GetPath(RootPath + "\" + Dirname)'这里只会先路径的
End If
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
End While
‘以下的不要或做函数调用也可以
Dim files As System.IO.FileInfo() = di.GetFiles()
Dim j As Integer = 0
While j < files.Length
Dim Filename As String
Dim FileModiTime As String
Filename = files(j).Name
FileModiTime = files(j).LastAccessTime
Response.Write(files(j).Name + " " + files(j).LastAccessTime + "<br>")
System.Math.Max(System.Threading.Interlocked.Increment(j), j - 1)
End While End Sub
Sub Page_Load()
If IsPostBack = False Then
Response.Write(RootPath + "\" + "<br>")
GetPath(RootPath)
End If
End Sub Public Sub GetPath(ByVal RootPath As String)
' Dim di As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(path)
Dim di = New System.IO.DirectoryInfo(RootPath)
Dim subDirs As System.IO.DirectoryInfo() = di.GetDirectories()
Dim files As System.IO.FileInfo() = di.GetFiles()
Dim i As Integer = 0
While i < files.Length
Dim Filename As String
Dim FileModiTime As String
Filename = files(i).Name
FileModiTime = files(i).LastAccessTime
Response.Write(i)
Response.Write(" ")
Response.Write(files(i).Name + " " + files(i).LastAccessTime + "<br>")
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) End While
Dim j As Integer = 0
While j < subDirs.Length Dim Dirname As String
Dirname = subDirs(j).Name
If Dirname <> "_vti_cnf" Then
Response.Write(j)
Response.Write(" ")
Response.Write(RootPath + "\" + Dirname + "\" + "<br>")
GetPath(RootPath + "\" + Dirname)
End If
System.Math.Max(System.Threading.Interlocked.Increment(j), j - 1)
End While
End Sub
谢谢,这样,我在开头加了根目录,就能根目录第一级,然后下面是根目录里的文件。然后可以一级一级正常显示。
因为这些数据都要insert到一个管理文件的数据表里的。
我试了。
没法转换成这种格式文件目录 文件名 最后修改时间
文件目录 文件名 最后修改时间
文件目录 文件名 最后修改时间
文件目录 文件名 最后修改时间
......
这种方式好像有难度。
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim RootPath As String
RootPath = "E:\Project"
If IsPostBack = False Then
GetPath(RootPath)
End If
End Sub
Public Sub GetPath(ByVal RootPath As String)
Dim di = New System.IO.DirectoryInfo(RootPath)
Dim subDirs As System.IO.DirectoryInfo() = di.GetDirectories()
Response.Write(RootPath + "\" + "<br>")
Dim files As System.IO.FileInfo() = di.GetFiles()
Dim j As Integer = 0
While j < files.Length
Dim Filename As String
Dim FileModiTime As String
Filename = files(j).Name
FileModiTime = files(j).LastAccessTime
Response.Write(files(j).Name + " " + files(j).LastAccessTime + "<br>")
System.Math.Max(System.Threading.Interlocked.Increment(j), j - 1)
End While Dim i As Integer = 0
While i < subDirs.Length
Dim Dirname As String
Dirname = subDirs(i).Name
If Dirname <> "_vti_cnf" Then
GetPath(RootPath + "\" + Dirname)
End If
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
End While
End Sub
End Class
Dim RootPath As String
RootPath = "E:\Project"
If IsPostBack = False Then
GetPath(RootPath)
End If
End Sub
Public Sub GetPath(ByVal RootPath As String)
Dim di = New System.IO.DirectoryInfo(RootPath)
Dim subDirs As System.IO.DirectoryInfo() = di.GetDirectories()
'Response.Write(RootPath + "\" + "<br>")
Dim files As System.IO.FileInfo() = di.GetFiles()
Dim j As Integer = 0
While j < files.Length
Dim Filename As String
Dim FileModiTime As String
Filename = files(j).Name
FileModiTime = files(j).LastAccessTime InsertMothed(RootPath, files(j).Name, files(j).LastAccessTime)
System.Math.Max(System.Threading.Interlocked.Increment(j), j - 1)
End While Dim i As Integer = 0
While i < subDirs.Length
Dim Dirname As String
Dirname = subDirs(i).Name
If Dirname <> "_vti_cnf" Then
GetPath(RootPath + "\" + Dirname)
End If
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
End While
End Sub Public Sub InsertMothed(ByVal RootPath As String, ByVal fileName As String, ByVal accessTime As Date)
Response.Write(" path:" + RootPath + " fileName:" + fileName + " " + accessTime + "<br>")
End Sub
但是我遇到了新问题。一下午了。webconfig中配置好了连接字符串。但是。这个文件里。我要用了。provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接一堆错误。根本就连不上去。
我一年多。没写这个东西了。能错成这幅德行天哪。。
因为是想在自己机器上面调试的。