?
Solved

Renaming a Folder

Posted on 2002-06-19
4
Medium Priority
?
590 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 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