📄 filesystem.vb
字号:
'' FileSystem.vb'' Author:' Mizrahi Rafael (rafim@mainsoft.com)' Guy Cohen (guyc@mainsoft.com)'' Copyright (C) 2002-2006 Mainsoft Corporation.' Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)'' Permission is hereby granted, free of charge, to any person obtaining' a copy of this software and associated documentation files (the' "Software"), to deal in the Software without restriction, including' without limitation the rights to use, copy, modify, merge, publish,' distribute, sublicense, and/or sell copies of the Software, and to' permit persons to whom the Software is furnished to do so, subject to' the following conditions:' ' The above copyright notice and this permission notice shall be' included in all copies or substantial portions of the Software.' ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE' LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION' OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'Imports SystemImports System.IOImports Microsoft.VisualBasic.CompilerServicesNamespace Microsoft.VisualBasic Public Module FileSystem ' Dir private members Private m_index As Integer Private m_files As FileInfo() Private m_dirs As DirectoryInfo() Private m_IsFile As Boolean = True Private ResStr As String = "" Private m_len As Integer = 0 Private m_IsLastElem As Boolean = Nothing Public Sub ChDir(ByVal Path As String) If ((Path = "") Or (Path Is Nothing)) Then Throw New System.ArgumentException("Argument 'Path' is Nothing or empty.") Dim fileinfo As New fileinfo(Path) If (fileinfo.Exists) Then Throw New System.IO.IOException("The Directory name is invalid.") Dim dirinfo As New DirectoryInfo(Path) If (dirinfo.Exists) Then Directory.SetCurrentDirectory(Path) Else Throw New System.IO.FileNotFoundException("Path " + "'" + Path + "'" + " not found.") End If End Sub Public Sub ChDrive(ByVal Drive As Char) If (Drive = "") Then Return If Not Char.IsLetter(Drive) Then Throw New System.ArgumentException("Argument 'Drive' is not a valid value.") Try Directory.SetCurrentDirectory(Drive + Path.VolumeSeparatorChar) Catch ex As DirectoryNotFoundException Throw New System.IO.IOException("Drive " + "'" + Drive + "'" + " not found.") End Try End Sub Public Sub ChDrive(ByVal Drive As String) If (Drive Is Nothing) Or (Drive = "") Then Return Dim ch As Char = CChar(Drive.Substring(0, 1)) FileSystem.ChDrive(ch) End Sub Public Function CurDir() As String Return Directory.GetCurrentDirectory() End Function Public Function CurDir(ByVal Drive As Char) As String If Not Char.IsLetter(Drive) Then Throw New System.ArgumentException("Argument 'Drive' is not a valid value.") Try Directory.SetCurrentDirectory(Drive + Path.VolumeSeparatorChar) Catch ex As DirectoryNotFoundException Throw New System.IO.IOException("Drive " + "'" + Drive + "'" + " not found.") End Try Return Path.GetFullPath(Convert.ToString(Drive)) End Function Public Function Dir() As String Dim strRes As String If (m_files Is Nothing) And (m_Dirs Is Nothing) Then Throw New System.ArgumentException("'Dir' function must first be called with a 'Pathname' argument.") ElseIf (m_IsLastElem) Then Throw New System.ArgumentException("'Dir' function must first be called with a 'Pathname' argument.") End If If m_index < m_len Then If m_IsFile Then strRes = m_files(m_index).Name Else strRes = m_dirs(m_index).Name End If m_index += 1 Else strRes = Nothing m_IsLastElem = True End If 'If m_index = m_len Then m_IsLastElem = True Return strRes End Function Public Function Dir(ByVal Pathname As String, Optional ByVal Attributes As Microsoft.VisualBasic.FileAttribute = 0) As String Dim str_parent_dir, str_pattern As String Dim last_ch As Integer Dim di As DirectoryInfo ResetInternal() last_ch = Pathname.LastIndexOf(Path.DirectorySeparatorChar) If (last_ch = -1) Then str_parent_dir = Directory.GetCurrentDirectory() Else str_parent_dir = Pathname.Substring(0, last_ch) End If str_pattern = Pathname.Substring(last_ch + 1, Pathname.Length - last_ch - 1) '' dir() doesn`t throw any exception just return "" di = New DirectoryInfo(str_parent_dir) If Not di.Exists Then Return ("") If (Attributes And FileAttributes.Directory) <> 0 Then If (str_pattern = "") Then m_dirs = di.GetDirectories() Else m_dirs = di.GetDirectories(str_pattern) End If If m_dirs.Length = 0 Then ResStr = "" Else m_IsFile = False m_len = m_dirs.Length ResStr = m_dirs(m_index).Name m_index += 1 End If Else If (str_pattern = "") Then m_files = di.GetFiles() Else m_files = di.GetFiles(str_pattern) End If If m_files.Length = 0 Then ResStr = "" Else m_IsFile = True m_len = m_files.Length ResStr = m_files(m_index).Name m_index += 1 End If End If If m_index - 1 = m_len Then m_IsLastElem = True If ResStr = "" Then '' reset all static members ResetInternal() End If Return ResStr End Function Private Sub ResetInternal() m_dirs = Nothing m_files = Nothing m_index = 0 m_len = 0 m_IsFile = Nothing m_IsLastElem = False End Sub Public Function EOF(ByVal FileNumber As Integer) As Boolean Throw New NotImplementedException End Function Public Function FileAttr(ByVal FileNumber As Integer) As Microsoft.VisualBasic.OpenMode Throw New NotImplementedException End Function Public Sub FileClose(ByVal ParamArray FileNumbers() As Integer) Throw New NotImplementedException End Sub Public Sub FileCopy(ByVal Source As String, ByVal Destination As String) '' seems File.Copy throw the same exceptions VB requires File.Copy(Source, Destination, True) End Sub Public Function FileDateTime(ByVal PathName As String) As Date If (PathName = "") Then Throw New System.IO.FileNotFoundException("File " + "'" + "'" + " not found.") Dim InvalidChars() As Char#If NET_2_0 Then InvalidChars = Path.GetInvalidPathChars()#Else InvalidChars = Path.InvalidPathChars#End If If Not (PathName.IndexOfAny(InvalidChars) = -1) Then Throw New System.ArgumentException("Argument 'PathName' is not a valid value.") End If Dim fi As New FileInfo(PathName) If (fi.Exists) Then Return fi.LastWriteTime Else Throw New System.IO.FileNotFoundException("File " + "'" + PathName + "'" + " not found.") End If End Function Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Boolean, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Byte, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Char, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Date, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Decimal, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Double, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Integer, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Long, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Short, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As Single, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As String, Optional ByVal RecordNumber As Long = -1, Optional ByVal StringIsFixedLength As Boolean = False) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As System.Array, Optional ByVal RecordNumber As Long = -1, Optional ByVal ArrayIsDynamic As Boolean = False, Optional ByVal StringIsFixedLength As Boolean = False) Throw New NotImplementedException End Sub Public Sub FileGet(ByVal FileNumber As Integer, ByRef Value As System.ValueType, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FileGetObject(ByVal FileNumber As Integer, ByRef Value As Object, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Function FileLen(ByVal PathName As String) As Long If ((PathName = "") Or (PathName Is Nothing)) Then Throw New System.IO.FileNotFoundException("File " + "'" + PathName + "'" + " not found.") Dim fi As New FileInfo(PathName) If (fi.Exists) Then Return fi.Length Else Throw New System.IO.FileNotFoundException("File " + "'" + PathName + "'" + " not found.") End If End Function Public Sub FileOpen(ByVal FileNumber As Integer, ByVal FileName As String, ByVal Mode As Microsoft.VisualBasic.OpenMode, Optional ByVal Access As Microsoft.VisualBasic.OpenAccess = Microsoft.VisualBasic.OpenAccess.[Default], Optional ByVal Share As Microsoft.VisualBasic.OpenShare = Microsoft.VisualBasic.OpenShare.[Default], Optional ByVal RecordLength As Integer = -1) Throw New NotImplementedException End Sub Public Sub FilePut(ByVal FileNumber As Integer, ByVal Value As Boolean, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FilePut(ByVal FileNumber As Integer, ByVal Value As Byte, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FilePut(ByVal FileNumber As Integer, ByVal Value As Char, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException End Sub Public Sub FilePut(ByVal FileNumber As Integer, ByVal Value As Date, Optional ByVal RecordNumber As Long = -1) Throw New NotImplementedException
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -