Module
Contents
Index 🔎︎

# MkDir Statement

在資料媒體中建立新目錄。

## 語法：

    MkDir Text As String

## 參數：

Text：任意字串型表示式，用於指定要建立的目錄之名稱和路徑。也可以使用 URL 表示法。

如果路徑未確定，則該目錄會在目前目錄下建立。

## 錯誤代碼：

5 無效的程序呼叫

76 找不到路徑

## 示例：

    Sub ExampleFileIO

    ' 有關檔案管理的函式範例

    Const sFile1 As String = "file://c|/autoexec.bat"

    Const sDir1 As String = "file://c|/Temp"

    Const sSubDir1 as String ="Test"

    Const sFile2 as String = "Copied.tmp"

    Const sFile3 as String = "Renamed.tmp"

    Dim sFile As String

        sFile = sDir1 + "/" + sSubDir1

        ChDir( sDir1 )

        If Dir(sSubDir1,16) ="" then ' 目錄是否存在？

            MkDir sSubDir1

            MsgBox sFile,0,"Create directory"

        End If

        sFile = sFile + "/" + sFile2

        FileCopy sFile1 , sFile

        MsgBox fSysURL(CurDir ()),0,"Current directory"

        MsgBox sFile & Chr(13) & FileDateTime( sFile ),0,"Creation time"

        MsgBox  sFile & Chr(13)& FileLen( sFile ),0,"File length"

        MsgBox  sFile & Chr(13)& GetAttr( sFile ),0,"File attributes"

        Name sFile As sDir1 + "/" + sSubDir1 + "/" + sFile3

        ' 在同一目錄中重新命名

        sFile = sDir1 + "/" + sSubDir1 + "/" + sFile3

        SetAttr( sFile, 0 ) ' 刪除所有屬性

        MsgBox sFile & Chr(13) & GetAttr( sFile ),0,"New file attributes"

        Kill sFile

        RmDir sDir1 + "/" + sSubDir1

    End Sub

    ' 將系統路徑轉換成 URL

    Function fSysURL( fSysFp As String ) As String

    Dim iPos As String

        iPos = 1

        iPos = Instr(iPos,fSysFp, getPathSeparator())

        Do While iPos > 0

            Mid( fSysFp, iPos , 1,"/")

            iPos = Instr(iPos+1,fSysFp, getPathSeparator())

        Loop

        ' DOS 中的冒號

        iPos = Instr(1,fSysFp,":")

        If iPos > 0 Then Mid( fSysFp, iPos , 1,"|")

        fSysURL = "file://" & fSysFp

    End Function