rename all files in FileListBox with a header string

Posted on 2005-04-28
Last Modified: 2010-04-05
How to rename all files in FileListBox with a header string?
Question by:fhtong
    LVL 27

    Expert Comment

    well, no delphi on hand, but i would guess

    uses shellapi;

    procedure TForm1.Button1Click(Sender: TObject);
    var I : Integer;
        opInfo : _SHFILEOPSTRUCT;
      for i := 0 to fileListBox1.Items.Count-1 do
         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                  
        opInfo.hNameMappings := nil;  // no mappings
        opInfo.fAnyOperationsAborted := False; //obsolete
        SHFileOperation(opInfo);  //do it

    just from head and really not tested -> typos possible

    meikl ;-)
    LVL 17

    Accepted Solution

    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

    Regards, Geo

    Author Comment

    Thanks, geobul.

    It works out fine.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    16 Experts available now in Live!

    Get 1:1 Help Now