Function GetFLoderFilesList(ByVal FloderPath As String) As ArrayList
Dim ArrList As New ArrayList
FloderPath = IIf(Mid(FloderPath, FloderPath.Length, 1) <> "\", FloderPath + "\", FloderPath)
Dim DirInfo As DirectoryInfo = New DirectoryInfo(FloderPath)
Dim Files() As FileInfo = DirInfo.GetFiles
Dim F(Files.Length) As String
Dim File As FileInfo
For Each File In Files
ArrList.Add(File.Name)
Next
Return ArrList
End Function
'遍历文件夹所有文件(包含子文件夹)
Public Shared Sub GetFloderAllFilesList(ByVal FloderPath As String, ByVal Root As Boolean, ByRef ArrList As ArrayList)
If Root = True Then
For Each SubFloder As String In Directory.GetDirectories(FloderPath)
GetFloderAllFilesList(SubFloder, False, ArrList)
Next
End If
For Each File As String In Directory.GetFiles(FloderPath)
ArrList.Add(File)
Next
End Sub
'复制文件,如果文件存在会覆盖文件
Function CopyFile(ByVal FileName As String, ByVal NewFileName As String) As Int16
On Error Resume Next
If System.IO.File.Exists(FileName) = True Then
If System.IO.File.Exists(NewFileName) = True Then System.IO.File.Delete(NewFileName)
System.IO.File.Copy(FileName, NewFileName)
CopyFile = 1
Else
CopyFile = 0
End If
End Function
'判断目录是否存在的函数 传入String值 返回Boolean值
Function DirExist(ByVal Str_Path As String) As Boolean
DirExist = System.IO.Directory.Exists(Str_Path)
End Function
'判断文件是否存在的函数 传入String值 返回Boolean值
Function FileExist(ByVal Str_File As String) As Boolean
On Error Resume Next
FileExist = System.IO.File.Exists(Str_File)
If Err.Number > 0 Then '错误判断用于文件存在而不能访问
FileExist = True
End If
End Function
'保存顺序文件
Function SaveTxtFile(ByVal FilePath As String, ByVal TxtList As ArrayList) As Int16
Dim F As System.IO.StreamWriter
F = FileIO.FileSystem.OpenTextFileWriter(FilePath, False)
For i As Long = 0 To TxtList.Count - 1
F.WriteLine(TxtList(i))
Next
F.Close()
End Function
'读取文本文件到ArrayList
Function ReadTxtFile(ByVal FileName As String, ByRef TxtArray As ArrayList) As Int16
Dim objReader As New StreamReader(FileName)
Dim sLine As String = ""
Dim arrText As New ArrayList()
Do
sLine = objReader.ReadLine()
If Not sLine Is Nothing Then
arrText.Add(sLine)
End If
Loop Until sLine Is Nothing
objReader.Close()
TxtArray = arrText
End Function
[本日志由 tiancao1001 于 2010-11-25 04:35 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |