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

ITS ALL ABOUT AUTOMATION

Saturday, 16 April 2016

AutoIt - Rename a file


Author Post Date Saturday, 16 April 2016
Since AutoIt lacks a FileRename function, we need to use FileMove () to rename a file.

Refer to AutoIt - Move file for details on file move function.

Example:

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>

;Assign the source file path to a variable.
Local $sSourceFilePath = @ScriptDir & "\temp.txt"

;Assign the destination path to a variable.
Local $sDestPath = @ScriptDir & "\temp_renamed.txt"

;Create temp.txt to rename.
If Not FileWrite($sSourceFilePath, "This is an example of using FileRename.") Then
    MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the file.")
EndIf

;Execute the move function to rename the file.
Local $iMoveStatus = FileMove($sSourceFilePath, $sDestPath, $FC_OVERWRITE + $FC_CREATEPATH)

;Display the status after checking the returned value.
If $iMoveStatus Then
    MsgBox($MB_SYSTEMMODAL, "", "Rename Success")
Else
    MsgBox($MB_SYSTEMMODAL, "", "Rename Failed")
EndIf

Related Posts




Interesting? Share and Let Others Know.

Post a Comment