#1 2019-01-05 16:26

ciltocruz
Member
Registered: 2019-01-05
Posts: 4

Add FolderName to newer files only + Continue w/ last found serial

Origin subject: I ask for very strange things?


Hi.

I have a case that I would like to know if it is possible to solve with this great software.


Yesterday I created a new folder named "Myfolder".
In it I put 5 photos and renamed them like this:

Myfolder_1.jpg
Myfolder_2.jpg
Myfolder_3.jpg
Myfolder_4.jpg
Myfolder_5.jpg

I also created a second folder named "MyDogs" with 3 photos.

MyDogs_1.jpg
MyDogs_2.jpg
MyDogs_3.jpg

All this I have done with 4 rules:
1. Delete all the original name.
2. Insert "_: File_FolderName: _" as a prefix.
3. Increase from 1 and 1 in 1.
4. Replace spaces with "_".

So far so easy, right?

Now the problem comes.
Today I have put 3 more photos in each folder.

Now I have the folders like this:

Myfolder:
 - IMG_20190104_1925.jpg
 - IMG_20190104_1930.jpg
 - IMG_20190104_1935.jpg
 - Myfolder_1.jpg
 - Myfolder_2.jpg
 - Myfolder_3.jpg
 - Myfolder_4.jpg
 - Myfolder_5.jpg

MyDogs:
 - IMG_20190104_2225.jpg
 - IMG_20190104_2230.jpg
 - IMG_20190104_2235.jpg
 - MyDogs_1.jpg
 - MyDogs_2.jpg
 - MyDogs_3.jpg

I add the folders in a massive way so that all the folders are renamed at the same time. I DO NOT ADD FOLDER TO FOLDER (This is not an option for me, I have too many folders)

I would like to rename the new files added to each folder but the series will continue in the last available file. I would also like to know how NOT to ADD the files that already have the name of the folder in their name. I tried to put an exclusion in the masks with the _: File_FolderName: _ but it does not work.

For example, in the first case, after adding the folders you would have to detect this:

Myfolder:
 - IMG_20190104_1925.jpg ---> Myfolder_6.jpg
 - IMG_20190104_1930.jpg ---> Myfolder_7.jpg
 - IMG_20190104_1935.jpg ---> Myfolder_8.jpg
 - Myfolder_1.jpg ---> do not rename
 - Myfolder_2.jpg ---> do not rename
 - Myfolder_3.jpg ---> do not rename
 - Myfolder_4.jpg ---> do not rename
 - Myfolder_5.jpg ---> do not rename

The program has known that the last element was "5" and must continue in 6.

The same would happen with the other folder.

Is all this possible?

Thanks.

(Subject line adjusted by Mod)

Last edited by Stefan (2019-01-05 18:07)

Offline

#2 2019-01-05 17:52

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Add FolderName to newer files only + Continue w/ last found serial

Hi and welcome!


For "work on new files only" perform this steps:

- Add all your files
- Right click context menu >  Mark > Mark by mask > IMG*
Now you work on newer files starting with IMG in name only.

(Or, on "Add Folders", utilize the "Filter Settings" > Mask Include: img* [x]Apply only..)


For "starting with the last serializing increment per folder"
me think this feature is missing.
Would be good to had that feature implemented:
Based on the current setting, ReNamer *could* well look for that last number, me think.


- - -

With the current feature set I would use:


(Have a backup!)


STEP-1

1) Insert: Insert ":File_FolderName:_" replacing current name (skip extension)
2) Serialize: Incremental from 100 repeat 1 step 1 (reset index if folder changes) as Suffix (skip extension)

Chose a higher serial number as the highest number over all folders, as I here use '100'.


Rename.

Information
6 file(s) successfully renamed.
9 file(s) skipped because unmarked.
[OK]


STEP-2

Mark all again.

Add a column "Path" and sort by path:

MyDogs_1.jpg
MyDogs_2.jpg
MyDogs_3.jpg
MyDogs_100.jpg
MyDogs_101.jpg
MyDogs_102.jpg



Remove the last rules.
Add new rules:
1) Delete: Delete from Delimiter "_" until the End (leave delimiter) (skip extension)
2) Serialize: Incremental from 1 repeat 1 step 1 (reset index if folder changes) as Suffix (skip extension)

Rename.

Done.



 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2019-01-05 18:35

ciltocruz
Member
Registered: 2019-01-05
Posts: 4

Re: Add FolderName to newer files only + Continue w/ last found serial

The solution is VERY GOOD. But it has some drawbacks.

In the first step, filter by IMG mask * I would rather have the option to EXCLUDE the files that have the name of the folder already incorporated (meta-tag does not work here). Why?

Because the new files some start with "IMG" others with "0000", others with "MVIMG", others with "numbers" ...
Therefore, I do not want to add with commas all the options because they can be several and unknown.

Then I would have to do the process for each of the different "beginnings". That's why I'd like to be able to exclude by folder / file name. It's possible?

Regarding recover the last index, I will test your method and yes, it would be fine as future feature in the application.

Thanks Stefan!

PD: Thanks for change de Title. Yours is more comprensible.

Last edited by ciltocruz (2019-01-05 18:53)

Offline

#4 2019-01-05 21:07

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Add FolderName to newer files only + Continue w/ last found serial

OK, another try with existent feature set, until den4b can add something new.


Use a PascalScript Rule:
- Have a backup!
- Add all wanted folders (without filter, just add all files)
- Sort somehow (e.g. by Name or by Path)
- Add below PascalScript
Only files not starting with parent folder name are processed for renaming
and next serial counter is calculated automatically by counting files which have already parent folder name.
- Preview
- Rename?



A PascalScript for your use case:
See http://www.den4b.com/wiki/ReNamer:Rules:PascalScript

{
 PascalScript for den4b ReNamer  v1(compare by first part till underscore)    05.01.2019
 http://www.den4b.com/forum/viewtopic.php?pid=10676#p10676
 Rename new added files with folder name and add serial number.
 Works on file pattern like:  foldername_xx.ext  , for ex.: MyDogs_1.jpg
 STEPS:
   Add all of your files.
   Sort by Name or by Path column.
   Add PascalScript rule with this script.
     Only files which not have the parent folder name already will be processed.
     Next Serial number will be calculated automatically.
}

var
  AmountOfFiles, Idx, I: Integer;
  CurrentFldName, LastFldName, FirstPart, SerialString, F: WideString;
  FileList,NameParts:  TWideStringArray;

begin
// // For each FOLDER:
  CurrentFldName := WideExtractFileName(WideExtractFileDir(FilePath));
  If( CurrentFldName <> LastFldName) Then
  begin
    SetLength(FileList, 0);
    Idx:=0;
     //WideScanDirForFiles(Dir, Files, Recursive, IncludeHidden, IncludeSystem, Mask);
    WideScanDirForFiles(WideExtractFileDir(FilePath), FileList, False, False, False, '*.*');
    AmountOfFiles := Length(FileList);
    //showmessage(CurrentFldName + ' has ' +  IntToStr(AmountOfFiles) + ' files in complete');

    for I:=0 to AmountOfFiles-1 do
    begin
      F := WideExtractFileName(FileList[i]);
      //showmessage( F);
      //WideSplitString( Input, Delimiter);
      NameParts := WideSplitString( F, '_');
      FirstPart :=   NameParts[0]
      If (FirstPart =  CurrentFldName ) Then
           Idx := Idx+1;
    end  ;
    //showmessage(CurrentFldName + ' has ' + IntToStr(Idx) + ' new added files');
end;
LastFldName := CurrentFldName;


// // For each file:
  NameParts := WideSplitString(FileName, '_');
  FirstPart := NameParts[0]
  // showmessage(FirstPart);

  If (FirstPart <>  CurrentFldName ) Then
    begin
      Idx := Idx+1 ;
      SerialString  := IntToStr(Idx);
      FileName := CurrentFldName + '_' + SerialString + WideExtractFileExt(FileName);
    end;
end.


HTH?:)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#5 2019-01-05 22:30

ciltocruz
Member
Registered: 2019-01-05
Posts: 4

Re: Add FolderName to newer files only + Continue w/ last found serial

Ok Stefan.

It works perfectly except for 2 very slight things.
Refine the script a bit.

I do an operation like this:

Folder Name: "My super dogs".
My photos inside the folder are "My_super_dogs". (with "_" instead of spaces)

1. How would you modify the pascalScript so that it works to compare the name of the folder but replacing spaces with "_"?
The Script works when the folder has only one name (Dogs), but not when it has more than 1 name, for example: "My family" because my files are "My_family_1" ...

I modified with "WideReplaceStr" to change the name of the folder but this I think does not work correctly to do the automatic renumbering since you are looking for the first "_" and there may be more than one in my case.

-----------------

The second thing is that I do not know how I can sort by 2 columns (like Excel for example); I would like to always sort by Name and then by path (several files that start with IMG have computer in the list mixing paths)

This is not very important, but it would be fine if the application could do it.

Thanks for all your support!

Offline

#6 2019-01-06 10:00

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Add FolderName to newer files only + Continue w/ last found serial

Ahh, now you came up with details wink

Folder Name: "My super dogs".
My photos inside the folder are "My_super_dogs". (with "_" instead of spaces)


OK, try that:
- Get "File with FolderName" by checking first few chars of file till FolderName length (here 14)
- and also by replacing spaces in taken FolderNames by underscore ("\My super dogs\" >>> "My_super_dogsxxxx.ext")


- Have a backup!
- Add all wanted folders (without filter, just add all files)
- Sort somehow (e.g. by Name or by Path)
- Add below PascalScript for your use case (See http://www.den4b.com/wiki/ReNamer:Rules:PascalScript)
Only files not starting with parent folder name are processed for renaming
and next serial counter is calculated automatically by counting files which have already parent folder name.
- Preview
- Rename?

{
 PascalScript for den4b ReNamer    v2(compare by length of folder name)  06.01.2019
 http://www.den4b.com/forum/viewtopic.php?pid=10676#p10676
 Rename new added files with folder name and add serial number.
 Works on file pattern like:  foldername_xx.ext -or- folder_name_xx.ext  
 STEPS:
   Add all of your files.
   Sort by Name or by Path column.
   Add PascalScript rule with this script.
     Only files which not have the parent folder name already will be processed.
     Next Serial number will be calculated automatically.
}

var
  AmountOfFiles, Idx, iFC, iCFL: Integer;
  CurrentFldName,CFNwUnderscores,LastFldName,FirstPart,SerialString,sFn: WideString;
  FileList:  TWideStringArray;

begin
// // For each FOLDER:
  CurrentFldName := WideExtractFileName(WideExtractFileDir(FilePath));
  iCFL := Length(CurrentFldName);
  //WideReplaceStr(input, OldPattern, NewPattern)
  CFNwUnderscores := WideReplaceStr(CurrentFldName,' ', '_');

  If(CurrentFldName <> LastFldName) Then
  begin
    SetLength(FileList, 0);
    Idx:=0;
     //WideScanDirForFiles(Dir, Files, Recursive, IncludeHidden, IncludeSystem, Mask);
    WideScanDirForFiles(WideExtractFileDir(FilePath), FileList, False, False, False, '*.*');
    AmountOfFiles := Length(FileList);
    //showmessage(CurrentFldName + ' has ' +  IntToStr(AmountOfFiles) + ' files in complete');

    for iFC:=0 to AmountOfFiles-1 do
    begin
      sFn := WideExtractFileName(FileList[iFC]);
      //showmessage(sFn);
      //WideCopy(input, StartIndex, AmountCount)
      FirstPart :=  WideCopy(sFn,0,iCFL);
      //showmessage(sFn);
      If (FirstPart =  CFNwUnderscores) Then
           Idx := Idx+1;
    end  ;
    //showmessage(CurrentFldName + ' has ' + IntToStr(Idx) + ' new added files');
end;
LastFldName := CurrentFldName;


// // For each file:
   FirstPart := WideCopy(FileName,1,iCFL);
  // showmessage(FirstPart);

  If (FirstPart <> CFNwUnderscores ) Then
    begin
      Idx := Idx+1;
      SerialString := IntToStr(Idx);
      FileName := CFNwUnderscores + '_' + SerialString + WideExtractFileExt(FileName);
    end;
end.


Better? big_smile


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#7 2019-01-06 23:33

ciltocruz
Member
Registered: 2019-01-05
Posts: 4

Re: Add FolderName to newer files only + Continue w/ last found serial

It works perfectly.

I keep it as a filter to execute it in the future.

Do not forget to include these proposals for future editions:
- Rename only new files from a folder
- Exclude from the mask by metatag
- To be able to continue with the last serial found in the same folder.
- Can order by several columns at the same time.

Thanks for everything Stefan.
If I find a problem, I'll tell you.

Regards!

Offline

Board footer

Powered by FluxBB