#1 2007-10-19 15:53

tintin
Member
Registered: 2007-10-19
Posts: 4

Same name for all files as an existing file in the folder

hello I have a folder with 4 files of different extensions. I want to modify the name of all files, for same name of an existing file in the folder. This is possible? thank anyway

Offline

#2 2007-10-20 13:38

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Same name for all files as an existing file in the folder

Yes, there are several different ways for doing this. You'll need to use PascalScript rule.

Few similar problems have already been discussed on the forum, for example: Rename "buddy" files

If you'll need help creating the script, you'll have to tell more details and give few examples.

Offline

#3 2007-10-20 16:18

tintin
Member
Registered: 2007-10-19
Posts: 4

Re: Same name for all files as an existing file in the folder

Thanks for answering. I will need your help if possible. I don’t now anything of pascal. I am creating a database separate by folders where have files with extension in jpg, dwg and .max. I intend that all files assumes same name that the file with the extension .max or one extension I chose.

Offline

#4 2007-10-21 14:09

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Same name for all files as an existing file in the folder

Forget about the "renaming buddy files" post, I found a better solution for you! big_smile

Simply drop all of your files into ReNamer, and use the code below. It will set name of every file to the same name as the first found file matching *.max mask and located in the same folder.

P.S. I removed your posted code because there is no need for it anymore. By the way, there was a slight mistake: you were trying to rename every file to the master file, without keeping the original extension - and that's why it didn't do anything.

P.P.S. I will move this topic to the "Help and Support" section later.

const
  MASTER_MASK = '*.max';

var
  MasterFile: WideString;
  
function FindMasterFile(const Dir: WideString): WideString;
var
  Files: TStringsArray;
begin 
  Result := '';
  SetLength(Files, 0);
  WideScanDirForFiles(Dir, Files,
    False, False, False, MASTER_MASK);
  if Length(Files) > 0 then
    Result := Files[0];
end;

begin
  MasterFile := FindMasterFile(WideExtractFileDir(FilePath));
  if MasterFile <> '' then
  if MasterFile <> FilePath then
  begin
    MasterFile := WideExtractBaseName(MasterFile);
    FileName := MasterFile + WideExtractFileExt(FileName);
  end;
end.

Offline

#5 2007-10-21 21:36

tintin
Member
Registered: 2007-10-19
Posts: 4

Re: Same name for all files as an existing file in the folder

Hi, you are extraordinary big_smile, work in the perfection, great help, saved me hours of tedium. This program is incredible or better it is perfect, thanks a lot lol

Offline

#6 2007-10-22 12:05

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Same name for all files as an existing file in the folder

Great big_smile  .. Hope this will start you up on the scripting, because it can be really powerful!

Offline

Board footer

Powered by FluxBB