<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/CreateDirectory?action=history&amp;feed=atom</id>
	<title>CreateDirectory - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/CreateDirectory?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=CreateDirectory&amp;action=history"/>
	<updated>2026-05-07T13:23:15Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=CreateDirectory&amp;diff=81920&amp;oldid=prev</id>
		<title>Mohab: Added redirect for arabic page</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=CreateDirectory&amp;diff=81920&amp;oldid=prev"/>
		<updated>2025-04-09T02:30:39Z</updated>

		<summary type="html">&lt;p&gt;Added redirect for arabic page&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:30, 9 April 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l89&quot;&gt;Line 89:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 89:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{Useful_Functions|Utility}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{Useful_Functions|Utility}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[ar:createDirectory]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Useful_Functions]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Useful_Functions]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-81917:rev-81920 --&gt;
&lt;/table&gt;</summary>
		<author><name>Mohab</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=CreateDirectory&amp;diff=81917&amp;oldid=prev</id>
		<title>Mohab: This function creates a directory in the resource's file system</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=CreateDirectory&amp;diff=81917&amp;oldid=prev"/>
		<updated>2025-04-09T01:49:37Z</updated>

		<summary type="html">&lt;p&gt;This function creates a directory in the resource&amp;#039;s file system&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Useful_Function}}&lt;br /&gt;
This function creates a directory at the specified path within the resource's file system. In MTASA, directories are implicitly created by creating a file within them, and this function handles that process automatically by creating and then removing a temporary file.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;bool createDirectory ( string directoryPath )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''directoryPath:''' A string representing the path of the directory to create, relative to the resource's root folder (e.g., &amp;quot;myfolder&amp;quot; or &amp;quot;myfolder/subfolder&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the directory was successfully created, ''false'' if the creation failed or if invalid arguments were passed.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
'''Directory Creation Utility'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function createDirectory(directoryPath)&lt;br /&gt;
    -- Check if directoryPath is provided and is a string&lt;br /&gt;
    if not directoryPath or type(directoryPath) ~= &amp;quot;string&amp;quot; then&lt;br /&gt;
        outputDebugString(&amp;quot;Error: Invalid directory path provided&amp;quot;, 1)&lt;br /&gt;
        return false&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Ensure the path ends with a forward slash&lt;br /&gt;
    if not directoryPath:match(&amp;quot;/$&amp;quot;) then&lt;br /&gt;
        directoryPath = directoryPath .. &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- MTASA file system requires a file to implicitly create the directory&lt;br /&gt;
    local tempFilePath = directoryPath .. &amp;quot;temp.txt&amp;quot;&lt;br /&gt;
    local file = fileCreate(tempFilePath)&lt;br /&gt;
    &lt;br /&gt;
    if file then&lt;br /&gt;
        -- Write something to the file (optional, but good practice to ensure creation)&lt;br /&gt;
        fileWrite(file, &amp;quot;Temporary file to create directory&amp;quot;)&lt;br /&gt;
        fileClose(file)&lt;br /&gt;
        &lt;br /&gt;
        -- Delete the temporary file to keep the directory clean&lt;br /&gt;
        fileDelete(tempFilePath)&lt;br /&gt;
        &lt;br /&gt;
        outputDebugString(&amp;quot;Directory created: &amp;quot; .. directoryPath)&lt;br /&gt;
        return true&lt;br /&gt;
    else&lt;br /&gt;
        outputDebugString(&amp;quot;Failed to create directory: &amp;quot; .. directoryPath, 1)&lt;br /&gt;
        return false&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Function source&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This function is a simple and efficient way to create directories in MTASA. It uses the MTASA file system’s behavior of implicitly creating directories when a file is created within them. A temporary file is created and then deleted to leave the directory empty and ready for use.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
This example shows how to call the `createDirectory` function to create a directory and provide feedback in the server console.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Create a directory called &amp;quot;logs&amp;quot; in the resource folder&lt;br /&gt;
local success = createDirectory(&amp;quot;logs&amp;quot;)&lt;br /&gt;
if success then&lt;br /&gt;
    outputConsole(&amp;quot;Directory 'logs' was created successfully!&amp;quot;)&lt;br /&gt;
else&lt;br /&gt;
    outputConsole(&amp;quot;Failed to create directory 'logs'.&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Create a nested directory structure&lt;br /&gt;
local nestedSuccess = createDirectory(&amp;quot;data/user/files&amp;quot;)&lt;br /&gt;
if nestedSuccess then&lt;br /&gt;
    outputConsole(&amp;quot;Nested directory 'data/user/files' was created successfully!&amp;quot;)&lt;br /&gt;
else&lt;br /&gt;
    outputConsole(&amp;quot;Failed to create nested directory 'data/user/files'.&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* This function must be written in a server-side script because file system operations like `fileCreate`, `fileWrite`, `fileClose`, and `fileDelete` are restricted to server-side in MTASA for security and synchronization reasons.&lt;br /&gt;
* The directory path is relative to the resource's root folder (e.g., `:resourceName/directoryPath/`).&lt;br /&gt;
* Ensure the resource has appropriate file permissions in the `meta.xml` file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;script src=&amp;quot;yourscript.lua&amp;quot; type=&amp;quot;server&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;file src=&amp;quot;*&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Author'': Mohab&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
* {{Useful_Functions|Utility}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Useful_Functions]]&lt;/div&gt;</summary>
		<author><name>Mohab</name></author>
	</entry>
</feed>