Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


filename collision

Posted on 2004-04-05
Medium Priority
Last Modified: 2010-05-19

  is there an algorithm that will prevent a rename collision. or should i say if i have a file name
  file1.txt and file2.txt   and i will rename file2.txt to file1.txt it will not prompt for filename exists
  but instead it will rename it to file1a.txt and so on and so forth?

Question by:aerokevs
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
1 Comment
LVL 17

Accepted Solution

mokule earned 500 total points
ID: 10756443
// procedure renames file OldName to NewName
// if file NewName exists the name is expanded with _NNN
// starting from _001
// until free number is found

procedure MyRenameFile(OldName,NewName: string);
  TempName,Ext : string;
  P: integer;
  Cnt: integer;
  if FileExists(NewName) then
    Ext := ExtractFileExt(NewName);
    P := Pos(Ext,NewName);
    TempName := Copy(NewName,1,P-1);
    Cnt := 1;
      NewName := Format('%s_%3.3d%s',[TempName,Cnt,Ext]);
    until not FileExists(NewName);

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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