Solved

Renaming a Folder

Posted on 2002-06-19
4
589 Views
Last Modified: 2012-06-21
What is the procedure for renaming a folder (directory) using Delphi code? Do I have to create a new folder, move the files and then delete the old folder? Or can I simply rename a folder?

I have been looking through the help files but I am not having any luck.

Thanks
0
Comment
Question by:bjames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:raidos
ID: 7092500
Use the MoveFile API if it's on the same disk, otherwise you WILL likely have to Create the Filestructure on the other disk for yourself...

Something like this:
While Not ALL_DONE Do Begin
  MkDir(DestinationFolders);
  CopyFile(SourceFile, TargetFile);
  If CopyOk Then
    DeleteFile(SourceFile);
End;

Regards
//raidos
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7092544
huh ?
simply use RenameFile(OldDirName, NewDirName);
works :)
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 100 total points
ID: 7092559
ok that one works only on the same disk
this works for all local disks (maybe network)

uses shellapi;

procedure TForm1.Button1Click(Sender: TObject);
var sh: SHFILEOPSTRUCT;
begin
     FillChar(sh, SizeOf(sh), 0);
     sh.wFunc:=FO_MOVE;
     sh.pFrom:=PChar(edit1.Text + #0);
     sh.pTo:=PChar(edit2.Text);
     SHFileOperation(sh);
end;
0
 

Author Comment

by:bjames
ID: 7092837
Perfect! Exactly what I needed.

Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question