LATEST UPDATES
ShareHolder Finder v0.9.3 is now released!!! Check Product Page for more details.
✉ info@automationdevelopers.com

ITS ALL ABOUT AUTOMATION

Sunday, 9 October 2016

AutoIt - How to Create a Folder


Author Post Date Sunday, 9 October 2016
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.

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

Related Posts





Interesting? Share and Let Others Know.

Post a Comment