Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

rename all files in FileListBox with a header string

How to rename all files in FileListBox with a header string?
0
fhtong
Asked:
fhtong
1 Solution
 
kretzschmarCommented:
well, no delphi on hand, but i would guess

uses shellapi;

procedure TForm1.Button1Click(Sender: TObject);
var I : Integer;
    opInfo : _SHFILEOPSTRUCT;
begin
  for i := 0 to fileListBox1.Items.Count-1 do
  begin
     opInfo.pFrom := YourPath+fileListBox1.Items[i];  //Source
    opInfo.pTo   := YourPath+YourPrefix+fileListBox1.Items[i];  //Destination
    opInfo.wFunc := FO_RENAME;  //Rename it
    opInfo.fFlags := FOF_NOCONFIRMATION  or //no confirmation
                   FOF_NOCONFIRMMKDIR or   //no confirmation                  
                   FOF_RENAMEONCOLLISION;
    opInfo.hNameMappings := nil;  // no mappings
    opInfo.fAnyOperationsAborted := False; //obsolete
    SHFileOperation(opInfo);  //do it
  end;
end;

just from head and really not tested -> typos possible

meikl ;-)
0
 
geobulCommented:
Or using RenameFile function:

with FileListBox1 do begin
  for i := 0 to Items.Count - 1 do begin
    if not RenameFile(Directory + '\' + Items[i], Directory + '\' + 'YourPrefix' + Items[i])  then begin
      // do something here when renaming is not possible
    end;
  end;
end;

Regards, Geo
0
 
fhtongAuthor Commented:
Thanks, geobul.

It works out fine.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now