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:
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
#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
- AutoIt - Check if a file exists
- AutoIt - Copy file
- AutoIt - Move file
- AutoIt - Delete file
- AutoIt - Check if a file or folder is Read Only
- AutoIt - Set a file or folder as Read Write
Interesting? Share and Let Others Know.
Post a Comment