Solved

Renaming a Folder

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

18 Experts available now in Live!

Get 1:1 Help Now