1<?xml version="1.0" encoding="UTF-8"?>
2
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23
24<helpdocument version="1.0">
25<meta>
26<topic id="textsbasicshared03020411xml" indexer="include" status="PUBLISH">
27<title id="tit" xml-lang="en-US">MkDir Statement [Runtime]</title>
28<filename>/text/sbasic/shared/03020411.xhp</filename>
29</topic>
30</meta>
31<body>
32<section id="mkdir">
33<bookmark xml-lang="en-US" branch="index" id="bm_id3156421"><bookmark_value>MkDir statement</bookmark_value>
34</bookmark>
35<paragraph role="heading" id="hd_id3156421" xml-lang="en-US" level="1" l10n="U" oldref="1"><link href="text/sbasic/shared/03020411.xhp" name="MkDir Statement [Runtime]">MkDir Statement [Runtime]</link></paragraph>
36<paragraph role="paragraph" id="par_id3147000" xml-lang="en-US" l10n="U" oldref="2">Creates a new directory on a data medium.</paragraph>
37</section>
38<paragraph role="heading" id="hd_id3148520" xml-lang="en-US" level="2" l10n="U" oldref="3">Syntax:</paragraph>
39<paragraph role="code" id="par_id3155150" xml-lang="en-US" l10n="U" oldref="4">MkDir Text As String</paragraph>
40<paragraph role="heading" id="hd_id3156027" xml-lang="en-US" level="2" l10n="U" oldref="5">Parameters:</paragraph>
41<paragraph role="paragraph" id="par_id3153750" xml-lang="en-US" l10n="U" oldref="6">
42<emph>Text:</emph> Any string expression that specifies the name and path of the directory to be created. You can also use <link href="text/sbasic/shared/00000002.xhp" name="URL notation">URL notation</link>.</paragraph>
43<paragraph role="paragraph" id="par_id3153311" xml-lang="en-US" l10n="U" oldref="7">If the path is not determined, the directory is created in the current directory.</paragraph>
44<embed href="text/sbasic/shared/00000003.xhp#errorcode"/>
45<embed href="text/sbasic/shared/00000003.xhp#err5"/>
46<embed href="text/sbasic/shared/00000003.xhp#err76"/>
47<paragraph role="heading" id="hd_id3155388" xml-lang="en-US" level="2" l10n="U" oldref="8">Example:</paragraph>
48<paragraph role="code" id="par_id3148473" xml-lang="en-US" l10n="U" oldref="9">Sub ExampleFileIO</paragraph>
49<paragraph role="code" id="par_id3149762" xml-lang="en-US" l10n="CHG" oldref="10">' Example for functions of the file organization</paragraph>
50<paragraph role="code" id="par_id3145610" xml-lang="en-US" l10n="U" oldref="11">Const sFile1 as String = "file://c|/autoexec.bat"</paragraph>
51<paragraph role="code" id="par_id3147264" xml-lang="en-US" l10n="U" oldref="12">Const sDir1 as String = "file://c|/Temp"</paragraph>
52<paragraph role="code" id="par_id3149669" xml-lang="en-US" l10n="U" oldref="13">Const sSubDir1 as String ="Test"</paragraph>
53<paragraph role="code" id="par_id3148663" xml-lang="en-US" l10n="U" oldref="14">Const sFile2 as String = "Copied.tmp"</paragraph>
54<paragraph role="code" id="par_id3154071" xml-lang="en-US" l10n="U" oldref="15">Const sFile3 as String = "Renamed.tmp"</paragraph>
55<paragraph role="code" id="par_id3150792" xml-lang="en-US" l10n="U" oldref="16">Dim sFile as String</paragraph>
56<paragraph role="code" id="par_id3154366" xml-lang="en-US" l10n="U" oldref="17">sFile = sDir1 + "/" + sSubDir1</paragraph>
57<paragraph role="code" id="par_id3149204" xml-lang="en-US" l10n="U" oldref="18">ChDir( sDir1 )</paragraph>
58<paragraph role="code" id="par_id3154217" xml-lang="en-US" l10n="U" oldref="19">If Dir(sSubDir1,16)="" then ' Does the directory exist ?</paragraph>
59<paragraph role="code" id="par_id3156423" xml-lang="en-US" l10n="U" oldref="20">MkDir sSubDir1</paragraph>
60<paragraph role="code" id="par_id3147228" xml-lang="en-US" l10n="U" oldref="21">MsgBox sFile,0,"Create directory"</paragraph>
61<paragraph role="code" id="par_id3153970" xml-lang="en-US" l10n="U" oldref="22">End If</paragraph>
62<paragraph role="code" id="par_id3148451" xml-lang="en-US" l10n="U" oldref="24">sFile = sFile + "/" + sFile2</paragraph>
63<paragraph role="code" id="par_id3155132" xml-lang="en-US" l10n="U" oldref="25">FileCopy sFile1 , sFile</paragraph>
64<paragraph role="code" id="par_id3153770" xml-lang="en-US" l10n="U" oldref="26">MsgBox fSysURL(CurDir()),0,"Current directory"</paragraph>
65<paragraph role="code" id="par_id3159154" xml-lang="en-US" l10n="U" oldref="27">MsgBox sFile &amp; Chr(13) &amp; FileDateTime( sFile ),0,"Creation time"</paragraph>
66<paragraph role="code" id="par_id3149484" xml-lang="en-US" l10n="U" oldref="28">MsgBox sFile &amp; Chr(13)&amp; FileLen( sFile ),0,"File length"</paragraph>
67<paragraph role="code" id="par_id3152885" xml-lang="en-US" l10n="U" oldref="29">MsgBox sFile &amp; Chr(13)&amp; GetAttr( sFile ),0,"File attributes"</paragraph>
68<paragraph role="code" id="par_id3152596" xml-lang="en-US" l10n="U" oldref="30">Name sFile as sDir1 + "/" + sSubDir1 + "/" + sFile3</paragraph>
69<paragraph role="code" id="par_id3153952" xml-lang="en-US" l10n="U" oldref="31">' Rename in the same directory</paragraph>
70<paragraph role="code" id="par_id3152576" xml-lang="en-US" l10n="U" oldref="33">sFile = sDir1 + "/" + sSubDir1 + "/" + sFile3</paragraph>
71<paragraph role="code" id="par_id3147426" xml-lang="en-US" l10n="U" oldref="34">SetAttr( sFile, 0 ) 'Delete all attributes</paragraph>
72<paragraph role="code" id="par_id3148647" xml-lang="en-US" l10n="U" oldref="35">MsgBox sFile &amp; Chr(13) &amp; GetAttr( sFile ),0,"New file attributes"</paragraph>
73<paragraph role="code" id="par_id3153363" xml-lang="en-US" l10n="U" oldref="36">Kill sFile</paragraph>
74<paragraph role="code" id="par_id3151113" xml-lang="en-US" l10n="U" oldref="37">RmDir sDir1 + "/" + sSubDir1</paragraph>
75<paragraph role="code" id="par_id3153157" xml-lang="en-US" l10n="U" oldref="38">end sub</paragraph>
76<paragraph role="code" id="par_id3150092" xml-lang="en-US" l10n="U" oldref="40">' Converts a system path in URL</paragraph>
77<paragraph role="code" id="par_id3147396" xml-lang="en-US" l10n="U" oldref="41">Function fSysURL( fSysFp as String ) as String</paragraph>
78<paragraph role="code" id="par_id3153878" xml-lang="en-US" l10n="U" oldref="42">Dim iPos As String</paragraph>
79<paragraph role="code" id="par_id3150420" xml-lang="en-US" l10n="U" oldref="43">iPos = 1</paragraph>
80<paragraph role="code" id="par_id3145253" xml-lang="en-US" l10n="U" oldref="44">iPos = Instr(iPos,fSysFp, getPathSeparator())</paragraph>
81<paragraph role="code" id="par_id3153415" xml-lang="en-US" l10n="U" oldref="45">do while iPos &gt; 0</paragraph>
82<paragraph role="code" id="par_id3153512" xml-lang="en-US" l10n="U" oldref="46">mid( fSysFp, iPos , 1,"/")</paragraph>
83<paragraph role="code" id="par_id3146899" xml-lang="en-US" l10n="U" oldref="47">iPos = Instr(iPos+1,fSysFp, getPathSeparator())</paragraph>
84<paragraph role="code" id="par_id3145652" xml-lang="en-US" l10n="U" oldref="48">loop</paragraph>
85<paragraph role="code" id="par_id3156276" xml-lang="en-US" l10n="U" oldref="49">' the colon with DOS</paragraph>
86<paragraph role="code" id="par_id3146913" xml-lang="en-US" l10n="U" oldref="50">iPos = Instr(1,fSysFp,":")</paragraph>
87<paragraph role="code" id="par_id3145640" xml-lang="en-US" l10n="U" oldref="51">if iPos &gt; 0 then mid( fSysFp, iPos , 1,"|")</paragraph>
88<paragraph role="code" id="par_id3155443" xml-lang="en-US" l10n="U" oldref="52">fSysURL = "file://" &amp; fSysFp</paragraph>
89<paragraph role="code" id="par_id3148995" xml-lang="en-US" l10n="U" oldref="53">End Function</paragraph>
90</body>
91</helpdocument>
92