DirCreate function is used to create a folder/ directory.
This function will also create all the parent directories, if they do not already exist.
In the below example, we will check if the folder already exist by checking the size using DirGetSize function. If the folder does not exist, we will create the folder and display the status.
DirCreate function returns 1 for success and 0 if there was an error creating the directory.
This function will also create all the parent directories, if they do not already exist.
In the below example, we will check if the folder already exist by checking the size using DirGetSize function. If the folder does not exist, we will create the folder and display the status.
DirCreate function returns 1 for success and 0 if there was an error creating the directory.
Example:
#include <MsgBoxConstants.au3>
;Assign the folder path to a variable.
Local $sFolderPath = "C:\AutomationDevelopers\Test"
; Check if the folder already exist by checking the size of directory.
; If the folder already exist, display a message and exit the script.
If DirGetSize($sFolderPath) <> -1 Then
MsgBox($MB_ICONINFORMATION, "", "Directory already exists!")
Exit
EndIf
;Create the folder and get the status.
Local $bStatus = DirCreate($sFolderPath)
;Display status message.
If $bStatus Then
MsgBox($MB_ICONINFORMATION, "Status", "Folder created successfully.")
Else
MsgBox($MB_ICONERROR, "Status", "Folder creation failed.")
EndIf
;Assign the folder path to a variable.
Local $sFolderPath = "C:\AutomationDevelopers\Test"
; Check if the folder already exist by checking the size of directory.
; If the folder already exist, display a message and exit the script.
If DirGetSize($sFolderPath) <> -1 Then
MsgBox($MB_ICONINFORMATION, "", "Directory already exists!")
Exit
EndIf
;Create the folder and get the status.
Local $bStatus = DirCreate($sFolderPath)
;Display status message.
If $bStatus Then
MsgBox($MB_ICONINFORMATION, "Status", "Folder created successfully.")
Else
MsgBox($MB_ICONERROR, "Status", "Folder creation failed.")
EndIf
Related Posts
- AutoIt - How to Copy a Folder
- AutoIt - How to Move a Folder
- AutoIt - How to Rename a Folder
- AutoIt - How to Delete a Folder
Interesting? Share and Let Others Know.
Post a Comment