MkDir 语句

MkDir Statement diagram

在数据媒体中创建新目录。

语法:


MkDir path

参数:

path: Any string expression that specifies the name and path of the directory to be created. You can also use URL notation.

如果不能确定路径,则在当前目录下创建指定的目录。

错误代码:

5 无效的过程调用

76 未找到路径

示例:


Sub ExampleFileIO
' 有关文件组织的函数示例
Const sFile1 As String = "file://c|/autoexec.bat"
Const sDir1 As String = "file://c|/Temp"
Const sSubDir1 As String ="测试"
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,"创建目录"
    End If
    sFile = sFile + "/" + sFile2
    FileCopy sFile1 , sFile
    MsgBox fSysURL(CurDir()),0,"当前目录"
    MsgBox sFile & Chr(13) & FileDateTime( sFile ),0,"Creation time"
    MsgBox sFile & Chr(13)& FileLen( sFile ),0,"文件长度"
    MsgBox sFile & Chr(13)& GetAttr( sFile ),0,"文件属性"
    Name sFile As sDir1 + "/" + sSubDir1 + "/" + sFile3
    ' 在同一个目录中重命名
    sFile = sDir1 + "/" + sSubDir1 + "/" + sFile3
    SetAttr( sFile, 0 ) ' 删除所有属性
    MsgBox sFile & Chr(13) & GetAttr( sFile ),0,"新文件属性"
    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

请支持我们!