BasicFileSystem.vb 17.3 KB
Newer Older
leaky114's avatar
leaky114 已提交
1 2 3 4 5 6
Imports System.IO
Imports System.Text
Imports System.Text.Encoding
Imports System.IO.FileStream
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.FileIO
leaky114's avatar
leaky114 已提交
7 8
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
leaky114's avatar
leaky114 已提交
9 10 11 12 13 14 15

Module BasicFileSystem

    '文件名结构
    Public Structure FileNameInfo
        Public Folder As String     '文件夹
        Public SigleName As String  '文件名+扩展名
leaky114's avatar
leaky114 已提交
16
        Public OnlyName As String  '仅文件名
leaky114's avatar
leaky114 已提交
17 18 19 20
        Public ExtensionName As String  '扩展名
    End Structure

    '读取文件(文件名)
leaky114's avatar
leaky114 已提交
21 22 23 24
    Public Function ReadTextFile(ByVal strFullFileName As String) As String
        Dim oStreamReader As New StreamReader(strFullFileName, Encoding.Default)
        Dim FileText = oStreamReader.ReadToEnd()
        oStreamReader.Close()
leaky114's avatar
leaky114 已提交
25 26 27 28
        Return FileText
    End Function

    '判断文件是否存在(文件名)
leaky114's avatar
leaky114 已提交
29
    Public Function IsFileExsts(ByVal strFullFileName As String) As Boolean
leaky114's avatar
leaky114 已提交
30
        IsFileExsts = IO.File.Exists(strFullFileName)
leaky114's avatar
leaky114 已提交
31 32 33
    End Function

    '判断文件夹是否存在(文件夹)
leaky114's avatar
leaky114 已提交
34
    Public Function IsDirectoryExists(ByVal strDirectoryFullName As String) As Boolean
leaky114's avatar
leaky114 已提交
35
        IsDirectoryExists = IO.Directory.Exists(strDirectoryFullName)
leaky114's avatar
leaky114 已提交
36 37 38
    End Function

    '获取文件所在文件夹(文件名)
leaky114's avatar
leaky114 已提交
39
    Public Function GetParentFolder(ByVal strFullFileName As String) As String
leaky114's avatar
leaky114 已提交
40 41 42 43 44 45 46 47 48 49 50
        'If IsFileExsts(strFullFileName) = True Then
        '    GetParentFolder = My.Computer.FileSystem.GetFileInfo(strFullFileName).DirectoryName
        'Else
        '    Dim i As Integer
        '    Dim strTemp As String
        '    strTemp = strFullFileName
        '    i = InStrRev(strTemp, "\")
        '    GetParentFolder = Strings.Left(strTemp, i - 1)
        'End If
        GetParentFolder = IO.Path.GetDirectoryName(strFullFileName)

leaky114's avatar
leaky114 已提交
51 52 53
    End Function

    '从全名中取出文件名,含扩展名(文件名)
leaky114's avatar
leaky114 已提交
54
    Public Function GetSingleName(ByVal strFullFileName As String) As String
leaky114's avatar
leaky114 已提交
55 56 57 58 59 60 61 62 63 64 65 66
        'If IsFileExsts(strFullFileName) = True Then
        '    GetSingleName = My.Computer.FileSystem.GetName(strFullFileName)
        'Else
        '    Dim p As Integer
        '    p = InStrRev(strFullFileName, "\")
        '    If p > 0 Then
        '        GetSingleName = Strings.Right(strFullFileName, Strings.Len(strFullFileName) - p)
        '    Else
        '        GetSingleName = ""
        '    End If
        'End If
        GetSingleName = IO.Path.GetFileName(strFullFileName)
leaky114's avatar
leaky114 已提交
67 68 69
    End Function

    '从全名中取出文件名简称,去除路径及扩展名(文件名)
leaky114's avatar
leaky114 已提交
70
    Public Function GetOnlyname(ByVal strFullFileName As String) As String
leaky114's avatar
leaky114 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        'If IsFileExsts(strFullFileName) = True Then
        '    Dim strFileName As String
        '    Dim strFileExtension As String

        '    strFileName = My.Computer.FileSystem.GetName(strFullFileName)
        '    strFileExtension = My.Computer.FileSystem.GetFileInfo(strFullFileName).Extension
        '    GetOnlyname = Microsoft.VisualBasic.Strings.Replace(strFileName, strFileExtension, "")
        'Else
        '    Dim i As Integer
        '    Dim strTemp As String
        '    strTemp = strFullFileName
        '    i = InStrRev(strTemp, "\")
        '    strTemp = Strings.Right(strTemp, Len(strTemp) - i)
        '    i = InStrRev(strTemp, ".")
        '    strTemp = Strings.Left(strTemp, i - 1)
        '    GetOnlyname = strTemp
        'End If
        GetOnlyname = IO.Path.GetFileNameWithoutExtension(strFullFileName)
leaky114's avatar
leaky114 已提交
89 90 91
    End Function

    '大写扩展名(文件名)
leaky114's avatar
leaky114 已提交
92
    Public Function UCaseGetFileExtension(ByVal strFullFileName As String) As String
leaky114's avatar
leaky114 已提交
93 94 95 96 97 98 99 100 101 102 103
        'If IsFileExsts(strFullFileName) = True Then
        '    UCaseGetFileExtension = UCase(My.Computer.FileSystem.GetFileInfo(strFullFileName).Extension)
        'Else
        '    Dim i As Integer
        '    Dim strTemp As String
        '    strTemp = strFullFileName
        '    i = InStrRev(strTemp, ".")
        '    strTemp = Strings.Right(strTemp, Len(strTemp) - i + 1)
        '    UCaseGetFileExtension = UCase(strTemp)
        'End If
        UCaseGetFileExtension = IO.Path.GetExtension(strFullFileName).ToUpper
leaky114's avatar
leaky114 已提交
104 105 106
    End Function

    '小写扩展名(文件名)
leaky114's avatar
leaky114 已提交
107
    Public Function LCaseGetFileExtension(ByVal strFullFileName As String) As String
leaky114's avatar
leaky114 已提交
108 109 110 111 112 113 114 115 116 117 118 119
        'If IsFileExsts(strFullFileName) = True Then
        '    LCaseGetFileExtension = LCase(My.Computer.FileSystem.GetFileInfo(strFullFileName).Extension)
        'Else
        '    Dim i As Integer
        '    Dim strTemp As String
        '    strTemp = strFullFileName
        '    i = InStrRev(strTemp, ".")
        '    strTemp = Strings.Right(strTemp, Len(strTemp) - i + 1)
        '    LCaseGetFileExtension = LCase(strTemp)
        'End If

        LCaseGetFileExtension = IO.Path.GetExtension(strFullFileName).ToLower
leaky114's avatar
leaky114 已提交
120 121 122
    End Function

    '获取filenameinfo结构(文件名)
leaky114's avatar
leaky114 已提交
123
    Public Function GetFileNameInfo(ByVal strFullFileName As String) As FileNameInfo
leaky114's avatar
leaky114 已提交
124
        Dim FNI As FileNameInfo = Nothing
leaky114's avatar
leaky114 已提交
125 126 127 128 129 130
        With FNI
            .Folder = GetParentFolder(strFullFileName)
            .SigleName = GetSingleName(strFullFileName)
            .ExtensionName = LCaseGetFileExtension(strFullFileName)
            .OnlyName = GetOnlyname(strFullFileName)
        End With
leaky114's avatar
leaky114 已提交
131 132 133 134 135

        Return FNI
    End Function

    '重命名(旧文件名,新文件名)
leaky114's avatar
leaky114 已提交
136 137
    Public Function ReFileName(ByVal strOldFullFileName As String, ByVal strNewFullFileName As String) As Boolean
        If IsFileExsts(strNewFullFileName) = False And IsFileExsts(strOldFullFileName) = True Then
leaky114's avatar
leaky114 已提交
138
            System.IO.File.Move(strOldFullFileName, strNewFullFileName)
leaky114's avatar
leaky114 已提交
139
            ReFileName = IsFileExsts(strNewFullFileName)
leaky114's avatar
leaky114 已提交
140 141 142
        Else
            ReFileName = False
        End If
leaky114's avatar
leaky114 已提交
143

leaky114's avatar
leaky114 已提交
144 145 146
    End Function

    '只变更文件名,不操作,仅返回新的文件名
leaky114's avatar
leaky114 已提交
147
    Public Function GetNewFileName(ByVal strOldFullFileName As String, ByVal strNewFileName As String) As String
leaky114's avatar
leaky114 已提交
148 149 150 151 152
        'Dim oFileNameInfo As FileNameInfo
        'oFileNameInfo = GetFileNameInfo(strOldFullFileName)

        'Dim strParentFolder As String
        'strParentFolder = oFileNameInfo.Folder  'GetParentFolder(OldFullFileName)
leaky114's avatar
leaky114 已提交
153

leaky114's avatar
leaky114 已提交
154 155
        'Dim strExtensionName As String
        'strExtensionName = oFileNameInfo.ExtensionName
leaky114's avatar
leaky114 已提交
156

leaky114's avatar
leaky114 已提交
157
        'GetNewFileName = strParentFolder & "\" & strNewFileName & strExtensionName
leaky114's avatar
leaky114 已提交
158

leaky114's avatar
leaky114 已提交
159 160 161 162
        Dim directoryPath As String = Path.GetDirectoryName(strOldFullFileName)
        Dim extension As String = Path.GetExtension(strOldFullFileName)

        GetNewFileName = Path.Combine(directoryPath, strNewFileName + extension)
leaky114's avatar
leaky114 已提交
163 164 165 166 167 168

        Return GetNewFileName

    End Function

    '只变更扩展名,不操作,仅返回新的文件名
leaky114's avatar
leaky114 已提交
169 170 171
    Public Function GetChangeExtension(ByVal strOldFullFileName As String, ByVal strNewExtensionName As String) As String
        'Dim oFileNameInfo As FileNameInfo
        'oFileNameInfo = GetFileNameInfo(strOldFullFileName)
leaky114's avatar
leaky114 已提交
172

leaky114's avatar
leaky114 已提交
173 174
        'Dim strParentFolder As String   '文件夹
        'strParentFolder = oFileNameInfo.Folder  'GetParentFolder(OldFullFileName)
leaky114's avatar
leaky114 已提交
175

leaky114's avatar
leaky114 已提交
176 177
        'Dim OnlyName As String     '仅文件名
        'OnlyName = oFileNameInfo.OnlyName
leaky114's avatar
leaky114 已提交
178

leaky114's avatar
leaky114 已提交
179
        'GetNewExtensionFileName = strParentFolder & "\" & OnlyName & strNewExtensionName
leaky114's avatar
leaky114 已提交
180

leaky114's avatar
leaky114 已提交
181
        GetChangeExtension = IO.Path.ChangeExtension(strOldFullFileName, strNewExtensionName)
leaky114's avatar
leaky114 已提交
182

leaky114's avatar
leaky114 已提交
183
        Return GetChangeExtension
leaky114's avatar
leaky114 已提交
184 185 186
    End Function

    '判断2个文件是否在同一文件夹(第一个文件名,第二个文件名)
leaky114's avatar
leaky114 已提交
187 188 189 190 191 192
    Public Function IsInSameFolder(ByVal strOneFullFileName As String, ByVal strTowFullFileName As String) As Boolean
        Dim strOneFileFolder As String
        Dim strTowFileForlder As String
        strOneFileFolder = GetParentFolder(strOneFullFileName)
        strTowFileForlder = GetParentFolder(strTowFullFileName)
        If strOneFileFolder = strTowFileForlder Then
leaky114's avatar
leaky114 已提交
193 194 195 196 197 198 199
            IsInSameFolder = True
        Else
            IsInSameFolder = False
        End If
    End Function

    '删除一个文件(文件名,是否删除到回收站选项)
leaky114's avatar
leaky114 已提交
200 201
    Public Function DelFile(ByVal strFullFileName As String, ByVal oRecycleOption As FileIO.RecycleOption) As Boolean
        If IsFileExsts(strFullFileName) Then
leaky114's avatar
leaky114 已提交
202
            Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(strFullFileName, FileIO.UIOption.OnlyErrorDialogs, oRecycleOption, FileIO.UICancelOption.ThrowException)
leaky114's avatar
leaky114 已提交
203
        End If
leaky114's avatar
leaky114 已提交
204
        DelFile = IsFileExsts(strFullFileName) Xor True
leaky114's avatar
leaky114 已提交
205 206 207
    End Function

    '仅删除一个文件夹中的文件(文件夹)
leaky114's avatar
leaky114 已提交
208
    Public Function DelOnlyFileInForlder(ByVal strFolder As String) As Boolean
leaky114's avatar
leaky114 已提交
209 210 211
        If IsDirectoryExists(strFolder) Then
            For Each file As String In IO.Directory.GetFiles(strFolder)
                DelFile(file, FileIO.RecycleOption.SendToRecycleBin)
leaky114's avatar
leaky114 已提交
212 213 214 215 216
            Next
        End If
    End Function

    '删除文件夹(文件夹)
leaky114's avatar
leaky114 已提交
217
    Public Function DelFolder(ByVal strFolder As String, ByVal intDeleteRecycleOption As Integer) As Boolean
leaky114's avatar
leaky114 已提交
218 219
        If IsDirectoryExists(strFolder) Then
            Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(strFolder, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, intDeleteRecycleOption)
leaky114's avatar
leaky114 已提交
220
            DelFolder = IsDirectoryExists(strFolder)
leaky114's avatar
leaky114 已提交
221 222 223 224 225 226
        Else
            DelFolder = False
        End If
    End Function

    '移动文件(源文件名,目标文件名)
leaky114's avatar
leaky114 已提交
227 228 229
    Public Function ReMoveFile(ByVal strSourceFileName As String, ByVal strDestinationFileName As String) As Boolean
        Dim strDestinationFolder As String
        strDestinationFolder = GetParentFolder(strDestinationFileName)
leaky114's avatar
leaky114 已提交
230 231 232

        If Not IO.Directory.Exists(strDestinationFolder) Then
            IO.Directory.CreateDirectory(strDestinationFolder)
leaky114's avatar
leaky114 已提交
233
        End If
leaky114's avatar
leaky114 已提交
234
        IO.File.Move(strSourceFileName, strDestinationFileName)
leaky114's avatar
leaky114 已提交
235
        Return IsFileExsts(strDestinationFileName)
leaky114's avatar
leaky114 已提交
236 237 238
    End Function

    '移动文件到文件夹(源文件名,目标文件夹)
leaky114's avatar
leaky114 已提交
239 240 241 242
    Public Function ReMoveFileToFolder(ByVal sourceFilePath As String, ByVal targetFolderPath As String) As Boolean

        If Not IO.Directory.Exists(targetFolderPath) Then
            IO.Directory.CreateDirectory(targetFolderPath)
leaky114's avatar
leaky114 已提交
243 244
        End If

leaky114's avatar
leaky114 已提交
245 246 247 248
        Dim targetFilePath As String = IO.Path.Combine(targetFolderPath, IO.Path.GetFileName(sourceFilePath))

        If sourceFilePath <> targetFolderPath Then
            IO.File.Move(sourceFilePath, targetFilePath)
leaky114's avatar
leaky114 已提交
249
        End If
leaky114's avatar
leaky114 已提交
250 251 252

        Return IsFileExsts(targetFilePath)

leaky114's avatar
leaky114 已提交
253 254 255
    End Function

    '扫描文件夹
leaky114's avatar
leaky114 已提交
256
    Public Sub GetAllFile(ByVal strBootFolder As String, ByVal strSourceFolder As String, ByVal olistbox As Object, Optional ByVal strExtension As String = ".idw") ' ListBox)
leaky114's avatar
leaky114 已提交
257
        ' 源文件夹父文件夹 ,源文件夹 , 目标文件夹
leaky114's avatar
leaky114 已提交
258 259 260
        Dim strDir As String() = System.IO.Directory.GetDirectories(strSourceFolder)
        Dim strFile As String() = System.IO.Directory.GetFiles(strSourceFolder)
        Dim oFileInfo As FileInfo
leaky114's avatar
leaky114 已提交
261 262 263 264 265 266 267 268 269 270
        Dim i As Integer
        'If strDir.Length > 0 Then
        '    For i = 0 To strDir.Length - 1
        '        Debug.Print(strDir(i))
        '    Next
        'End If

        If strFile.Length > 0 Then
            For i = 0 To strFile.Length - 1
                'Debug.Print(strFile(i))
leaky114's avatar
leaky114 已提交
271
                oFileInfo = My.Computer.FileSystem.GetFileInfo(strFile(i))
leaky114's avatar
leaky114 已提交
272
                If (LCase(oFileInfo.Extension) = strExtension) And (Strings.InStr(oFileInfo.FullName, "OldVersions") = 0) Then
leaky114's avatar
leaky114 已提交
273 274 275
                    If IsItemInListView(olistbox, oFileInfo.FullName) = False Then
                        olistbox.Items.Add(oFileInfo.FullName)
                    End If
leaky114's avatar
leaky114 已提交
276 277 278 279 280
                End If
            Next
        End If
        If strDir.Length > 0 Then
            For i = 0 To strDir.Length - 1
leaky114's avatar
leaky114 已提交
281
                GetAllFile(strBootFolder, strDir(i), olistbox, strExtension)
leaky114's avatar
leaky114 已提交
282 283 284 285 286
            Next
        End If
    End Sub

    '删除旧文件
leaky114's avatar
leaky114 已提交
287
    Public Sub DelOldFile(ByVal strBootFolder As String, ByVal DeletePermanently As Boolean)
leaky114's avatar
leaky114 已提交
288
        '  目标文件夹
leaky114's avatar
leaky114 已提交
289
        Dim strDir As String() = System.IO.Directory.GetDirectories(strBootFolder)
leaky114's avatar
leaky114 已提交
290 291 292 293 294 295
        Dim i As Integer

        On Error Resume Next
        If strDir.Length > 0 Then
            For i = 0 To strDir.Length - 1
                Debug.Print(strDir(i))
leaky114's avatar
leaky114 已提交
296 297 298
                Dim oDirectoryInfo As DirectoryInfo
                oDirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(strDir(i))
                If oDirectoryInfo.Name = "OldVersions" Then
leaky114's avatar
leaky114 已提交
299
                    '按文件删除,速度太慢,改为直接删除文件夹
leaky114's avatar
leaky114 已提交
300
                    Dim arrFile As String() = System.IO.Directory.GetFiles(strDir(i))
leaky114's avatar
leaky114 已提交
301

leaky114's avatar
leaky114 已提交
302 303
                    For Each strFullFileName As String In arrFile
                        SetStatusBarText(strFullFileName)
leaky114's avatar
leaky114 已提交
304 305
                        Select Case DeletePermanently
                            Case True   '永久删除
leaky114's avatar
leaky114 已提交
306
                                DelFile(strFullFileName, FileIO.RecycleOption.DeletePermanently)
leaky114's avatar
leaky114 已提交
307
                            Case False  '删除到垃圾箱
leaky114's avatar
leaky114 已提交
308
                                DelFile(strFullFileName, FileIO.RecycleOption.SendToRecycleBin)
leaky114's avatar
leaky114 已提交
309
                        End Select
leaky114's avatar
leaky114 已提交
310

leaky114's avatar
leaky114 已提交
311
                    Next
leaky114's avatar
leaky114 已提交
312 313 314 315 316 317 318 319 320 321

                End If
                DelOldFile(strDir(i), DeletePermanently)
            Next

        End If

    End Sub

    '删除旧文件夹   (  目标文件夹)
leaky114's avatar
leaky114 已提交
322
    Public Sub DelOldDirectory(ByVal strBootFolder As String, ByVal DeleteRecycleOption As Integer)
leaky114's avatar
leaky114 已提交
323 324
        On Error Resume Next

leaky114's avatar
leaky114 已提交
325
        Dim strDir As String() = System.IO.Directory.GetDirectories(strBootFolder)
leaky114's avatar
leaky114 已提交
326 327 328 329 330
        Dim i As Integer

        If strDir.Length > 0 Then
            For i = 0 To strDir.Length - 1
                Debug.Print(strDir(i))
leaky114's avatar
leaky114 已提交
331 332 333
                Dim oDirectoryInfo As DirectoryInfo
                oDirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(strDir(i))
                If oDirectoryInfo.Name = "OldVersions" Then
leaky114's avatar
leaky114 已提交
334 335

                    '按文件夹名删除
leaky114's avatar
leaky114 已提交
336 337
                    Dim strDirectoryName As String
                    strDirectoryName = oDirectoryInfo.FullName
leaky114's avatar
leaky114 已提交
338

leaky114's avatar
leaky114 已提交
339
                    SetStatusBarText(strDirectoryName)
leaky114's avatar
leaky114 已提交
340

leaky114's avatar
leaky114 已提交
341
                    DelFolder(strDirectoryName, DeleteRecycleOption)
leaky114's avatar
leaky114 已提交
342 343 344 345 346 347 348 349

                End If
                DelOldDirectory(strDir(i), DeleteRecycleOption)
            Next

        End If
    End Sub

leaky114's avatar
leaky114 已提交
350
    '检查 listview中是否存在重复项,再添加
leaky114's avatar
leaky114 已提交
351
    Public Function IsItemInListView(ByVal oListiView As ListView, ByVal strItem As String) As Boolean
leaky114's avatar
leaky114 已提交
352

leaky114's avatar
leaky114 已提交
353 354 355 356 357
        '检查为空值时跳过
        If strItem = "" Then
            Return False
        End If

leaky114's avatar
leaky114 已提交
358 359
        For Each oListViewItem As ListViewItem In oListiView.Items
            If oListViewItem.Text = strItem Then
leaky114's avatar
leaky114 已提交
360
                IsItemInListView = True
leaky114's avatar
leaky114 已提交
361 362 363
                Exit Function
            End If
        Next
leaky114's avatar
leaky114 已提交
364
        IsItemInListView = False
leaky114's avatar
leaky114 已提交
365 366 367 368

    End Function

    '移出 listview 中的选择项
leaky114's avatar
leaky114 已提交
369
    Public Sub ListViewDel(ByVal oListView As ListView)
leaky114's avatar
leaky114 已提交
370 371 372 373 374 375 376
        If oListView.SelectedItems.Count > 0 Then
            ' 遍历 ListView 中的所有选择项。
            For Each item As ListViewItem In oListView.SelectedItems
                ' 从 ListView 中移除选择项。
                oListView.Items.Remove(item)
            Next
        End If
leaky114's avatar
leaky114 已提交
377 378
    End Sub

leaky114's avatar
leaky114 已提交
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
    Public Function SetNewFile(ByVal strFullFileName As String, ByVal strFilter As String) As String
        If IsFileExsts(strFullFileName) = True Then
            Dim msg As MsgBoxResult = MsgBox("已存在文件: " & strFullFileName & "  是否覆盖(是)或另存为(否)?", MsgBoxStyle.Question + MsgBoxStyle.YesNoCancel)
            Select Case msg
                Case MsgBoxResult.Yes
                    Return strFullFileName
                Case MsgBoxResult.No
                    Dim oSaveFileDialog As New SaveFileDialog
                    With oSaveFileDialog
                        .Title = "选择文件"
                        .Filter = strFilter  ' "AutoCAD文件(*.dwg)|*.dwg"
                        .InitialDirectory = GetParentFolder(strFullFileName)
                        If .ShowDialog = DialogResult.OK Then
                            Return .FileName
                        Else
                            Return "取消"
                        End If
                    End With
                Case MsgBoxResult.Cancel
                    Return "取消"
            End Select
        Else
            'Dim oSaveFileDialog As New SaveFileDialog
            'With oSaveFileDialog
            '    .Title = "选择文件"
            '    .Filter = strFilter  ' "AutoCAD文件(*.dwg)|*.dwg"
            '    .InitialDirectory = Microsoft.VisualBasic.FileIO.SpecialDirectories.Desktop
            '    If .ShowDialog = DialogResult.OK Then
            '        Return .FileName
            '    Else
            '        Return "取消"
            '    End If
            'End With

        End If
        Return strFullFileName
    End Function

    '设置文件只读属性
    Public Function SetFileReadOnly(ByVal strFullFileName As String, ByVal bIsReadOnly As Boolean) As Boolean
        If IsFileExsts(strFullFileName) = False Then
            Return False
        End If

        Dim myFile As New FileInfo(strFullFileName)
        If bIsReadOnly = True Then  '设置
            myFile.Attributes = FileAttributes.ReadOnly
            Return True
        Else    'false为可写
            myFile.Attributes = FileAttributes.Normal
            Return True
        End If
    End Function

    '获取文件只读属性
    Public Function GetFileReadOnly(ByVal strFullFileName As String) As Boolean
        Dim myFile As New FileInfo(strFullFileName)
        GetFileReadOnly = myFile.IsReadOnly
    End Function



leaky114's avatar
leaky114 已提交
441
End Module