|
| 1 | +Imports System |
| 2 | +Imports PigObjFsLib |
| 3 | +Module Program |
| 4 | + Public goFS As New pFileSystemObject |
| 5 | + Sub Main(args As String()) |
| 6 | + Do While True |
| 7 | + Console.WriteLine("*******************") |
| 8 | + Console.WriteLine("Main menu") |
| 9 | + Console.WriteLine("*******************") |
| 10 | + Console.WriteLine("Press Q to Exit") |
| 11 | + Console.WriteLine("Press A to pFileSystemObject") |
| 12 | + Console.WriteLine("Press B to pTextStream") |
| 13 | + Console.WriteLine("*******************") |
| 14 | + Select Case Console.ReadKey().Key |
| 15 | + Case ConsoleKey.Q |
| 16 | + Exit Do |
| 17 | + Case ConsoleKey.A |
| 18 | + Do While True |
| 19 | + Console.WriteLine("*******************") |
| 20 | + Console.WriteLine("Menu pFileSystemObject") |
| 21 | + Console.WriteLine("*******************") |
| 22 | + Console.WriteLine("Press Q to Up") |
| 23 | + Console.WriteLine("Press A to GetFile") |
| 24 | + Console.WriteLine("Press B to GetFolder") |
| 25 | + Console.WriteLine("Press C to FileExists") |
| 26 | + Console.WriteLine("Press D to FolderExists") |
| 27 | + Console.WriteLine("Press E to CreateFolder") |
| 28 | + Console.WriteLine("*******************") |
| 29 | + Select Case Console.ReadKey().Key |
| 30 | + Case ConsoleKey.Q |
| 31 | + Exit Do |
| 32 | + Case ConsoleKey.A |
| 33 | + Dim strFilePath As String |
| 34 | + Console.WriteLine("#################") |
| 35 | + Console.WriteLine("Enter the file path, such as " & GetCurrDirFristFile()) |
| 36 | + strFilePath = Console.ReadLine() |
| 37 | + If strFilePath = "" Then |
| 38 | + strFilePath = GetCurrDirFristFile() |
| 39 | + End If |
| 40 | + Dim oFile As pFile = goFS.GetFile(strFilePath) |
| 41 | + Console.WriteLine("DateCreated: " & oFile.DateCreated) |
| 42 | + Console.WriteLine("DateLastModified: " & oFile.DateLastModified) |
| 43 | + Console.WriteLine("Name: " & oFile.Name) |
| 44 | + Console.WriteLine("Path: " & oFile.Path) |
| 45 | + Console.WriteLine("#################") |
| 46 | + Case ConsoleKey.B |
| 47 | + Dim strFolderPath As String |
| 48 | + Console.WriteLine("#################") |
| 49 | + Console.WriteLine("Enter the file folder, such as " & goFS.AppPath) |
| 50 | + strFolderPath = Console.ReadLine() |
| 51 | + If strFolderPath = "" Then |
| 52 | + strFolderPath = goFS.AppPath |
| 53 | + End If |
| 54 | + Dim oFolder As pFolder = goFS.GetFolder(strFolderPath) |
| 55 | + Console.WriteLine("DateCreated: " & oFolder.DateCreated) |
| 56 | + Console.WriteLine("DateLastModified: " & oFolder.DateLastModified) |
| 57 | + Console.WriteLine("Name: " & oFolder.Name) |
| 58 | + Console.WriteLine("Path: " & oFolder.Path) |
| 59 | + Console.WriteLine("#################") |
| 60 | + Case ConsoleKey.C |
| 61 | + Dim strFilePath As String |
| 62 | + Console.WriteLine("#################") |
| 63 | + Console.WriteLine("Enter the file path, such as " & GetCurrDirFristFile()) |
| 64 | + strFilePath = Console.ReadLine() |
| 65 | + If strFilePath = "" Then |
| 66 | + strFilePath = GetCurrDirFristFile() |
| 67 | + End If |
| 68 | + Console.WriteLine("FileExists: " & goFS.FileExists(strFilePath)) |
| 69 | + Console.WriteLine("#################") |
| 70 | + Case ConsoleKey.D |
| 71 | + Dim strFolderPath As String |
| 72 | + Console.WriteLine("#################") |
| 73 | + Console.WriteLine("Enter the file folder, such as " & goFS.AppPath) |
| 74 | + strFolderPath = Console.ReadLine() |
| 75 | + If strFolderPath = "" Then |
| 76 | + strFolderPath = goFS.AppPath |
| 77 | + End If |
| 78 | + Console.WriteLine("FolderExists: " & goFS.FolderExists(strFolderPath)) |
| 79 | + Console.WriteLine("#################") |
| 80 | + Case ConsoleKey.E |
| 81 | + Dim strFolderPath As String, strDefaPath As String |
| 82 | + Console.WriteLine("#################") |
| 83 | + With goFS |
| 84 | + strDefaPath = .AppPath & "a" & .OsPathSep & "b" |
| 85 | + Console.WriteLine("Enter the file folder, such as " & strDefaPath) |
| 86 | + End With |
| 87 | + strFolderPath = Console.ReadLine() |
| 88 | + If strFolderPath = "" Then |
| 89 | + strFolderPath = strDefaPath |
| 90 | + End If |
| 91 | + goFS.CreateFolder(strFolderPath) |
| 92 | + Console.Write("CreateFolder: ") |
| 93 | + If goFS.LastErr = "" Then |
| 94 | + Console.WriteLine("OK") |
| 95 | + Else |
| 96 | + Console.WriteLine(goFS.LastErr) |
| 97 | + End If |
| 98 | + Console.WriteLine("#################") |
| 99 | + End Select |
| 100 | + Loop |
| 101 | + Case ConsoleKey.B |
| 102 | + Do While True |
| 103 | + Console.WriteLine("*******************") |
| 104 | + Console.WriteLine("Menu pTextStream") |
| 105 | + Console.WriteLine("*******************") |
| 106 | + Console.WriteLine("Press Q to Up") |
| 107 | + Console.WriteLine("Press A to Read File") |
| 108 | + Console.WriteLine("Press B to Write File") |
| 109 | + Console.WriteLine("*******************") |
| 110 | + Select Case Console.ReadKey().Key |
| 111 | + Case ConsoleKey.Q |
| 112 | + Exit Do |
| 113 | + Case ConsoleKey.A |
| 114 | + Dim strFilePath As String |
| 115 | + Console.WriteLine("#################") |
| 116 | + Console.WriteLine("Enter the file path, such as " & GetCurrDirFristFile()) |
| 117 | + strFilePath = Console.ReadLine() |
| 118 | + If strFilePath = "" Then |
| 119 | + strFilePath = GetCurrDirFristFile() |
| 120 | + End If |
| 121 | + If goFS.FileExists(strFilePath) = False Then |
| 122 | + Console.WriteLine(strFilePath & " not found.") |
| 123 | + Else |
| 124 | + Dim oTextStream As pTextStream |
| 125 | + Console.WriteLine("OpenTextFile(" & strFilePath & ")...") |
| 126 | + oTextStream = goFS.OpenTextFile(strFilePath, pFileSystemObject.pIOMode.ForReading, False) |
| 127 | + If goFS.LastErr <> "" Then |
| 128 | + Console.WriteLine(goFS.LastErr) |
| 129 | + Else |
| 130 | + Do While Not oTextStream.AtEndOfStream |
| 131 | + Console.WriteLine(oTextStream.ReadLine) |
| 132 | + Loop |
| 133 | + oTextStream.Close() |
| 134 | + End If |
| 135 | + End If |
| 136 | + Console.WriteLine("#################") |
| 137 | + Case ConsoleKey.B |
| 138 | + Dim strFilePath As String, strDefaFile As String |
| 139 | + Console.Write("Enter the file path, such as ") |
| 140 | + If goFS.IsWindows = True Then |
| 141 | + strDefaFile = "C:\Temp\TestPigFsDemo.txt" |
| 142 | + Else |
| 143 | + strDefaFile = "/Temp/TestPigFsDemo.txt" |
| 144 | + End If |
| 145 | + Console.WriteLine(strDefaFile) |
| 146 | + strFilePath = Console.ReadLine() |
| 147 | + If strFilePath = "" Then |
| 148 | + strFilePath = strDefaFile |
| 149 | + End If |
| 150 | + Dim oTextStream As pTextStream |
| 151 | + Console.WriteLine("OpenTextFile(" & strFilePath & ")...") |
| 152 | + oTextStream = goFS.OpenTextFile(strFilePath, pFileSystemObject.pIOMode.ForWriting, True) |
| 153 | + If goFS.LastErr <> "" Then |
| 154 | + Console.WriteLine(goFS.LastErr) |
| 155 | + Else |
| 156 | + oTextStream.WriteLine("WriteLine") |
| 157 | + oTextStream.WriteBlankLines(2) |
| 158 | + oTextStream.Close() |
| 159 | + Console.WriteLine("OK") |
| 160 | + End If |
| 161 | + End Select |
| 162 | + Loop |
| 163 | + End Select |
| 164 | + |
| 165 | + Loop |
| 166 | + End Sub |
| 167 | + |
| 168 | + Public Function GetCurrDirFristFile() As String |
| 169 | + Dim oFolder As pFolder |
| 170 | + oFolder = goFS.GetFolder(goFS.AppPath) |
| 171 | + GetCurrDirFristFile = "" |
| 172 | + For Each objFile In oFolder.Files |
| 173 | + If Not objFile Is Nothing Then |
| 174 | + GetCurrDirFristFile = objFile.Path |
| 175 | + Exit For |
| 176 | + End If |
| 177 | + Next |
| 178 | + End Function |
| 179 | + |
| 180 | +End Module |
0 commit comments