Description
Use the CreateFolder
method to create a folder at the specified location.
Declaration
Applies To
The method is applied to the following object:
Parameters
The method has the following parameter:
Path
Specifies the fully qualified path where a new folder should be created. If the path includes folders that do not exist, they will be created as well.
The path may or may not include a trailing backslash (\). You can add a trailing backslash to or remove it from the path by using the IncludeTrailingBackSlash
or ExcludeTrailingBackSlash
method.
Result Value
If the creation succeeds, the method returns zero, otherwise, it returns the error code. To get a description that corresponds to the given error code, you can use the aqUtils.SysErrorMessage
method. A complete list of error codes is provided in the System Error Codes article in the MSDN library.
Example
The code below creates a new C:\MyFiles\MyFolder folder, checks whether the folder has been created successfully and adds a new file to this folder.
JavaScript, JScript
function Test()
{
var sFolder = "C:\\MyFiles\\MyFolder\\";
var sFile = sFolder + "FileName.txt";
// Creates the folder and checks if it has been created successfully
if (aqFileSystem.CreateFolder(sFolder) == 0)
// Creates a file in that folder
aqFile.Create(sFile);
else
Log.Error("Could not create the folder " + sFolder);
}
Python
def Test():
sFolder = "C:\\MyFiles\\MyFolder\\"
sFile = sFolder + "FileName.txt"
# Creates the folder and checks if it has been created successfully
if aqFileSystem.CreateFolder(sFolder) == 0:
# Creates a file in that folder
aqFile.Create(sFile)
else:
Log.Error("Could not create the folder " + sFolder)
VBScript
Sub Test
Dim sFolder, sFile
sFolder = "C:\MyFiles\MyFolder\"
sFile = sFolder + "FileName.txt"
' Creates the folder and checks if it has been created successfully
If aqFileSystem.CreateFolder(sFolder) = 0 Then
' Creates a file in that folder
aqFile.Create sFile
Else
Log.Error "Could not create the folder " & sFolder
End If
End Sub
DelphiScript
procedure Test;
var sFolder, sFile;
begin
sFolder := 'C:\MyFiles\MyFolder\';
sFile := sFolder + 'FileName.txt';
// Creates the folder and checks if it has been created successfully
if aqFileSystem.CreateFolder(sFolder) = 0 then
// Creates a file in that folder
aqFile.Create(sFile)
else
Log.Error('Could not create the folder ' + sFolder);
end;
C++Script, C#Script
function Test()
{
var sFolder = "C:\\MyFiles\\MyFolder\\";
var sFile = sFolder + "FileName.txt";
// Creates the folder and checks if it has been created successfully
if (aqFileSystem["CreateFolder"](sFolder) == 0)
// Creates a file in that folder
aqFile["Create"](sFile);
else
Log["Error"]("Could not create the folder " + sFolder);
}
See Also
Working With Files From Scripts
aqFileSystem.DeleteFolder Method
aqFileSystem.GetCurrentFolder Method
aqFileSystem.SetCurrentFolder Method
aqFile.Create Method
aqUtils.SysErrorMessage Method