ファイルシステムオブジェクト


  FS.bas




  

Global FileSystem As Variant

' ******************************************************
' 初期化
' ******************************************************
Public Function FsInit()

    If Not IsObject(FileSystem) Then
        Set FileSystem = CreateObject("Scripting.FileSystemObject")
    End If

End Function

' ******************************************************
' ファイルの読み込みオープン
' ******************************************************
Public Function FsReadOpen(strFileName As String) As Object

    Call FsInit

    Set FsReadOpen = FileSystem.OpenTextFile(strFileName, 1)

End Function

' ******************************************************
' ファイルの書き込みオープン
' ******************************************************
Public Function FsWriteOpen(strFileName As String) As Object

    Call FsInit

    Set FsWriteOpen = FileSystem.CreateTextFile(strFileName, 1)

End Function

' ******************************************************
' クローズ
' ******************************************************
Public Function FsClose(ByRef fp As Object)

    fp.Close
    Set fp = Nothing

End Function

' ******************************************************
' EOF
' ******************************************************
Public Function FsEof(ByRef fp As Object) As Boolean

    FsEof = fp.AtEndOfStream

End Function

' ******************************************************
' ファイルの複写
' ******************************************************
Public Function FsCopy(strFrom As String, strTo As String)

    Call FsInit

    FileSystem.CopyFile strFrom, strTo, True

End Function

' ******************************************************
' テンポラリディレクトリの取得
' ******************************************************
Public Function FsGetTmp() As String

    Call FsInit

    FsGetTmp = FileSystem.GetSpecialFolder(2)

End Function

' ******************************************************
' 存在チェック
' ******************************************************
Public Function FsExist(Spec As String, nType As Integer) As Boolean

    Call FsInit
    
    Select Case nType
        Case 0  ' ファイル
            FsExist = FileSystem.FileExists(Spec)
        Case 1  ' ディレクトリ
            FsExist = FileSystem.FolderExists(Spec)
        Case 2  ' ドライブ
            FsExist = FileSystem.DriveExists(Spec)
    End Select

End Function

' ******************************************************
' ディレクトリ作成
' ******************************************************
Public Function FsMkDir(Spec As String)

    Call FsInit

    Dim i
    Dim strParent As String

    strParent = Spec

    On Error Resume Next
    FileSystem.CreateFolder Spec
    On Error GoTo 0
    If FsExist(Spec, 1) Then
        Exit Function
    End If
    strParent = FileSystem.GetParentFolderName(Spec)
    If strParent = "" Then
        Exit Function
    End If
    
    Do While Not FsExist(strParent, 1)
        
        strParent = FileSystem.GetParentFolderName(strParent)
        If strParent = "" Then
            Exit Do
        End If
        
        On Error Resume Next
        FileSystem.CreateFolder strParent
        On Error GoTo 0
    
        strParent = Spec
        On Error Resume Next
        FileSystem.CreateFolder strParent
        On Error GoTo 0
    
    Loop

End Function

' ******************************************************
' ディレクトリ削除
' ******************************************************
Public Function FsRmDir(Spec As String, Force As Boolean)

    Call FsInit

    On Error Resume Next
    FileSystem.DeleteFolder Spec, Force
    On Error GoTo 0

End Function


' ******************************************************
' カレントディレクトリ取得
' ******************************************************
Public Function FsGetCurDir() As String

    Call FsInit

    FsGetCurDir = FileSystem.GetAbsolutePathName(".")

End Function

' ******************************************************
' 指定ディレクトリ内のファイル一覧
' ******************************************************
Public Function FsGetFiles(Grid As Object, TargetDir As String)

    Call FsInit
    
    Dim oFolder
    Dim oFc
    Dim oFcw

    Set oFolder = FileSystem.GetFolder(TargetDir)
    Set oFc = oFolder.Files
    
    Grid.Cols = 3
    Grid.Clear
    
    Dim i
    
    i = 1
    
    For Each oFcw In oFc
        Grid.Rows = i + 1
        Grid.TextMatrix(i, 1) = oFcw.Name
        i = i + 1
    Next

    Grid.Sort = 1

End Function

' ******************************************************
' 使用されていないドライブを取得
' ******************************************************
Public Function FsGetFreeDrive(nType As Long) As String

    Call FsInit
    
    Dim i
    Dim TargetDrive

    If nType = 0 Then
        For i = &H44 To &H5A
            On Error Resume Next
            Set TargetDrive = FileSystem.GetDrive(Chr(i) & ":")
            If Err.Number <> 0 Then
                FsGetFreeDrive = Chr(i) & ":"
                Exit Function
            End If
        Next
    Else
        For i = &H5A To &H44 Step -1
            On Error Resume Next
            Set TargetDrive = FileSystem.GetDrive(Chr(i) & ":")
            If Err.Number <> 0 Then
                FsGetFreeDrive = Chr(i) & ":"
                Exit Function
            End If
        Next
    End If

End Function

' ******************************************************
' ファイルの削除
' ******************************************************
Public Function FsDeleteFile(TargetFile) As String

    Call FsInit

    Call FileSystem.DeleteFile(TargetFile, True)

End Function

  







  処理サンプル

  

Private Sub Command1_Click()


    Set fp = FsReadOpen(App.Path & "\" & "test.txt")
    Set ofp = FsWriteOpen(App.Path & "\" & "test2.txt")

    Do While Not FsEof(fp)
    
        ofp.WriteLine fp.ReadLine
    
    Loop

    FsClose ofp
    FsClose fp

End Sub

  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[PROvbFunction]
CCBot/2.0 (https://commoncrawl.org/faq/)
24/09/13 21:58:10
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube