#1 2019-07-26 06:44

dannician
Member
Registered: 2019-07-06
Posts: 34

Serialize only if more than one file in a folder

Is there a way to add a number to the end of each file only after more than one file in the folder is present?

Offline

#2 2019-07-26 10:17

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

Re: Serialize only if more than one file in a folder

It should be possible with the Pascal Script rule.

Can you provide a complete example of the input and desired output file paths?

Offline

#3 2019-07-26 17:14

dannician
Member
Registered: 2019-07-06
Posts: 34

Re: Serialize only if more than one file in a folder

What I mean to say is that if there is only one picture in a folder it does not get _# attached to the end but if there are two then they both get a number. If this interferes with the final sort order than i will accept single images having numbers but if not that would be pretty cool.

Original.....

Folder1
    Image.jpg

Folder2
     Image.jpg
     Image.jpg

Folder3
     Image.jpg

Folder4
     Image.jpg
     Image.jpg
     Image.jpg
     Image.jpg

Result.......

New Folder   
     Folder1_Image.jpg
     Folder2_Image_1.jpg
     Folder2_Image_2.jpg
     Folder3_Image.jpg
     Folder4_Image_1.jpg
     Folder4_Image_2.jpg
     Folder4_Image_3.jpg
     Folder4_Image_4.jpg

Hope that helps.

Offline

#4 2019-07-29 22:00

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

Re: Serialize only if more than one file in a folder

The whole thing can be achieved with a Pascal Script rule, but we'll try to keep as much as possible to the standard rules.

Serializing files according to their folder can be accomplished with the standard rules. Use the Serialize rule with the "reset index if folder changes" option. It will leave you with one last task - stripping out number suffixes from files which came from 1-file folders - that will have to be done by a Pascal Script rule.

Note that the files are sorted by the Path column.

renamer-dannician.png

And here is that magic script:

const
  FileMask = '*.jpg';
  StripChars = '_0123456789';
var
  Files: TWideStringArray;
begin
  SetLength(Files, 0);
  WideScanDirForFiles(WideExtractFileDir(FilePath),
    Files, False, False, False, FileMask);
  if Length(Files) = 1 then
  begin
    FileName := WideExtractFilePath(FileName) +
      WideTrimCharsRight(WideExtractBaseName(FileName), StripChars) +
      WideExtractFileExt(FileName);
  end;
end.

Offline

Board footer

Powered by FluxBB