---
url: >-
  /statelake/scripting-reference/classes/file-connection-class-tflofilecon/filecon.movefile.md
---

# FileCon.MoveFile

When a **File Definition** is used with an **Action**, the **MoveFile** function can be called to move a file to a new location and/or to give a file a new name.

If **aDestPath** is the same as the file's current path, then **MoveFile** renames the file within that directory path.

**MoveFile** returns **True** if the move or rename is successful, but **MoveFile** returns **False** if the move or rename fails. **MoveFile** will fail if the specified values are not allowed as a file path or file name.

The **MoveFile** function realigns the **File Con** with this new file location and/or name. Any further functionality such as **Transports** will use the new moved file.

For example, when the **File Con** audit functionality occurs, it will take the file from the moved name and/or location and move it to the corresponding audit folder on completion of the **Action**.

If the target directory path does not exist, then **Statelake** will attempt to create it automatically.

Other file utility functions can be reviewed at [File Functions](/statelake/scripting-reference/functions-and-procedures/file-functions/).

For file activities that do not involve any source or destination files, please reference [Windows File Functions](/statelake/scripting-reference/functions-and-procedures/file-functions/windows-file-functions).

**Declaration**: function MoveFile (const aDestPath, aDestName: string): boolean;

An example that utilises several **FileCon** objects, including **FileCon.MoveFile**.

```pascal
procedure OnStartMapEvent;
var
  vFilePath, vFileName, vFileExt, vTimestamp: string;
  vMovedOK: boolean;
begin
 //split full file name into path, name, and extension portions ...
  vFilePath := ExtractFilePath(Source.FileCon.CurrentFileName);
  vFileName := ExtractFileName(Source.FileCon.CurrentFileName);
  vFileExt := ExtractFileExt(Source.FileCon.CurrentFileName);

 //remove file extension
  vFileName := ChangeFileExt(vFileName, '');

 //then build a timestamp, to add to the file name ...
  vTimestamp := FormatDateTime('yyyymmddhhnnss', Now);
  vFileName := vFileName + '_' + vTimestamp + vFileExt;
  vMovedOK := Source.FileCon.MoveFile(vFilePath, vFileName);
 if vMovedOK then
    LogInfo('Timestamp appended to file name')
 else
    LogError('Error appending timestamp to file name');
end;
```
