11 Vote

Delphi: Rename Folder

Tutorial by Delphian | Last update on 2021-05-12 | Created on 2012-08-09

In this tutorial I would like to show you, how you can rename a directory with Delphi.

We are using the ShellApi from Windows for this, so we have to write the unit ShellApi to our uses-clause:


After that, we define a procedure called RenameFolder, with which we are able to rename the folder "FolderOld" to "FolderNew":

procedure RenameFolder(FolderOld, FolderNew: string);
   ShellInfo: TSHFileOpStruct;
   ShellInfo.Wnd   := 0;
   ShellInfo.wFunc := FO_RENAME;
   ShellInfo.pFrom := PChar(FolderOld);
   ShellInfo.pTo   := PChar(FolderNew);

Finally, here is a possible call of our procedure. Here we are renaming the folder "Folder" to "NewName":

procedure TForm1.Button1Click(Sender: TObject);
   RenameFolder('C:\Folder', 'C:\NewName');

Have fun with renaming!


About the Author

AvatarThe author has not added a profile short description yet.
Show Profile


Related Topics

Rename File to its Folder Name

Tutorial | 0 Comments

Delphi: System-Wide HotKey

Tutorial | 1 Comment

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.