Solved

Renaming a Folder

Posted on 2002-06-19
4
586 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now