#1 2013-05-22 21:26

bhadkow
Member
Registered: 2013-05-22
Posts: 5

Extension + RegEx + UserInput

Hi guys, i stumbled upon ReNamer recently, its incredible - so thanks a ton wink

Here is my unique puzzle..., I am using wget to get a bunch of files with no extensions. File type - image (.jpg).

Part 1:

Before,  filename(alphanumeric)=12345678-A00001   
            filename(alphanumeric)=12345678-A00002
            ........
            filename(alphanumeric)=12345678-A00xxx
            ........
            ........
            filename(alphanumeric)=85434312-A00001
            filename(alphanumeric)=85434312-A00002
            .........
            filename(alphanumeric)=85434312-A00yyy
            .........

After,   
for files with 12345678 -----> First Image 0001.jpg
                                         First Image 0002.jpg
                                         ......
                                         First Image 0xxx.jpg
                                          ......
                                          ......
for files with 85434312 -----> Nineteenth Image 0001.jpg
                                         ........
                                         Nineteenth Image 0yyy.jpg


where x,y are numbers. The final names "First Image", "Nineteenth Image" are in a text file.  I want,

1) first rule to change the extension then,
2) use UserInput along with RegEx to get the first line of .txt for first set of x files,
                                                              second line of .txt for next set of y files and so on.




Part 2: can ReNamer move each set of files to a unique folder and rename it with the same filename, as taken from the .txt?

Its complicated, and beyond my scope. All help is appreciated.

Thanks. smile

Offline

#2 2013-05-23 06:58

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

Re: Extension + RegEx + UserInput

Hi b. and welcome to the community.

B wrote:

1) first rule to change the extension then,
2) use UserInput along with RegEx to get the
first line of .txt for first set of x files,
second line of .txt for next set of y files and so on

For 1) use Rule 'Extension'

For 2)
A: select your first group of files '123' (perhaps check out the context menu in the files list)
B: use rule 'UserInput' and paste the wanted names in.
C: take a Preview and Rename
D: select the second group '854' and...

See our fine wiki for more >>> http://www.den4b.com/wiki/ReNamer


Create List for UserInput
If you have no list with names for every file but one line of example name only,
then create that list first with a text editor or a spread sheet like:
den4b ReNamer create list to rename files with spread sheet







For your Part2:
Please do not mix-up threads with different question.
Open a separate one for each or search the forum for existent.
For example also our fine wiki can aid you >>> http://www.den4b.com/wiki/ReNamer:Renam … her_folder


-


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 2013-05-23 09:17

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Extension + RegEx + UserInput

I think how I would do it is...

1.
Delete from start until delimiter "=".
Replace "-A" with "\".
If you rename now you'll get this files inside new folders.

2.
Remove these files from the list and Add the created folders to it (probably you'll need to change filter settings for this).
UserInput, paste the folder names.
Rename with the new names.

3.
To bring the files back to where you started add them again (keep in mind the filter settings one more time).
Insert "..\:File_FolderName: " and rename, and they will move back one folder putting the name of the folder in them.

4.
Delete (manually) the empty folders...

Last edited by SafetyCar (2013-05-23 09:20)


If this software has helped you, consider getting your pro version. :)

Offline

#4 2013-05-23 15:50

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

Re: Extension + RegEx + UserInput

After some time passed, I guess the user wants...


FROM:
12345678-A00001
12345678-A00002
12345678-A00003
85434312-A00001
85434312-A00002
85434312-A00003

TO:
First Image 0001.jpg
First Image 0002.jpg
First Image 0003.jpg
Nineteenth Image 0001.jpg
Nineteenth Image 0002.jpg
Nineteenth Image 0003.jpg

(own new name, depended to first 8 signs from old name, by keeping current numbering and adding a extension)

This can be done by using a PascalScript like this:
(visit our wiki for an how-to using PascalScripts)

//// if name starts with 'foo', then rename with 'bar' ////
var
  Part1, Part2 : WideString;
  
begin
      // Add your code here
      
      ////Get parts of filename: //e.g.: 12345678-A00001
        Part1 := Copy(FileName,0,8); //e.g.: 12345678
        Part2 := Copy(FileName,12,4);//e.g.: 0001

      ////FROM: 12345678-A00001
      ////TO:  First Image 0001.jpg
        if Part1 = '12345678' then
           Part1 := 'First Image ';

      ////FROM: ABCdef13-A00001
      ////TO: Second Image 0001.jpg
        if Part1 = 'ABCdef13' then
           Part1 := 'Second Image ';


      //// and so on     ....
     ////


      ////FROM:     85434312-A00001
      ////TO: Nineteenth Image 0001.jpg
        if Part1 = '85434312' then
           Part1 := 'Nineteenth Image ';

            
      ////compose new file name:
      FileName := Part1 + Part2 + '.jpg';
end.

Next I will try to write a script which reads the old<>new name pattern
from an text file which contains lines like:
old patternA ? new patternA
old patternB ? new patternB
old patternC ? new patternC

I think that code flies already around the forum....


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 2013-05-23 18:05

bhadkow
Member
Registered: 2013-05-22
Posts: 5

Re: Extension + RegEx + UserInput

Thanks for the suggestions guys but, the thing is, its much more complex than that. Let me explain clearly, i have say 300 sets ,each with ~ 300 files. i.e ~ 90000 files in total!

All the files in a set are numbered 1 to xxx. Set A may have 250, set B 225 , set C 270 (its random for each set). All these files are in a single folder.  They are distinguished by unique the eight digit number in the filename.  Now, i have all the 300 set names in a .txt file - line by line (so, 300 name - 300 lines).

eg: 1st set (xxx files starting with) --->  filename@&l=12345678-A0001      to    1st line in .txt ---->  The Great Mystery (jun-2003) A0001
      150th set (yyy files starting with) --->  filename@&l=45675679-A0001      to    150th line in .txt ---->  Random World (may-2009) A0001            likewise for the rest.

Offline

#6 2013-05-23 21:17

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

Re: Extension + RegEx + UserInput

.

bhadkow wrote:

All the files in a set are numbered 1 to xxx. Set A may have 250, set B 225 , set C 270 (its random for each set).
They are distinguished by unique the eight digit number in the filename.

I guess that are unimportant information, because....

bhadkow wrote:

All these files are in a single folder. 
Now, i have all the 300 set names in a .txt file - line by line (so, 300 name - 300 lines).


That is great and make things easy.

Rename from text file, file by file, line by line

Every one line in text file holds the new name for the file in the ReNamer list view at the very same position.
File List ===== List file
old name1 = new name1
old name2 = new name2
old name3 = new name3

BE SURE to have both list in same order.
Utilize Preview before actual Renaming.
Best work with copies of your files or have a backup.


Let's go....

FROM ordered list of current file names without gaps:
old filename one
old filename two
old filename three
old filename four
old filename five
old filename six
old filename seven
old filename eight
old filename nine
old filename ten
old filename eleven
old filename twelve

While HAVEing a list like this, with one line with future name for each current file name:
new name one
new name two
new name three
new name four
new name five
new name six
new name seven
new name eight
new name nine
new name ten

as 'NewFilenamesList.txt' in the folder of ReNamer



Wanted to Rename TO:
(by reading 'NewFilenamesList.txt' line by line and adding numbering plus extension our own)
new name one 0001.jpg
new name two 0002.jpg
new name three 0003.jpg
new name four 0004.jpg
new name five 0005.jpg
new name six 0006.jpg
new name seven 0007.jpg
new name eight 0008.jpg
new name nine 0009.jpg
new name ten 0010.jpg
###### E R R O R  no more lines in list file ###### 0011.jpg
###### E R R O R  no more lines in list file ###### 0012.jpg



We can USE this PascalScript:
(see our wiki for a how-to >>> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript)

var
  iLine                     : Integer;
  sListFile, sLine, sSerial : String;
 
begin
  ////Read line from file:
   sListFile := 'NewFilenamesList.txt';         //// list file in ReNamer folder
 //sListFile := 'C:\Temp\NewFilenamesList.txt'; //// list file in C:\Temp\
        
  iLine := iLine + 1;
  sLine := FileReadLine(sListFile, iLine);
        
  //if(sLine='')then Exit; //skip this file
    if(sLine='')then sLine := '###### E R R O R  no more lines in list file ######';; //inform the user

  ////Pad digits numbering serializing padding:			  
    sSerial := IntToStr(iLine);
    while Length(sSerial) < 4 do
          sSerial := '0'+sSerial;
        
  //compose new file name:
    FileName := sLine + ' ' + sSerial + '.jpg';
end.


big_smile big_smile big_smile If that helps somebody, then please donate to Denis. Or help four others too yourself in the next 30 days big_smile big_smile 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 2013-05-24 05:28

bhadkow
Member
Registered: 2013-05-22
Posts: 5

Re: Extension + RegEx + UserInput

sample files list before renaming... (9 files)

watermark@&lid=1002856570-I00001
watermark@&lid=1002856570-I00002
watermark@&lid=1002856570-I00003
watermark@&lid=1003516165-I00001
watermark@&lid=1003516165-I00002
watermark@&lid=1043157131-I00001
watermark@&lid=1043157131-I00002
watermark@&lid=1043157131-I00003
watermark@&lid=1043157131-I00004

actual names in names.txt (line by line - 3 lines)
Book One
Book Two
Book Three

final names of the files after working with renamer should be.

Book One 01.jpg
Book One 02.jpg
Book One 03.jpg
Book Two 01.jpg
Book Two 02.jpg
Book Three 01.jpg
Book Three 02.jpg
Book Three 03.jpg
Book Three 04.jpg


Sorry, for not giving a clear example earlier.
Please note , above example has only 9 files. In reality i have more than 50000 files.

Offline

#8 2013-05-24 06:50

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

Re: Extension + RegEx + UserInput

after all

Still two questions.

Which method should we use?

1.)
Mode A
IF found "1002856570" rename with fixed name "Book One"
IF found "1003516165" rename with fixed name "Book Two"
IF found "1043157131" rename with fixed name"Book Three "

OR
Mode B
IF found "1002856570", rename with first line from list file, no matter what this is
IF found "1003516165",  increase counter and rename with second line from list file, no matter what this is
IF found "1043157131",  increase counter and rename with third line from list file, no matter what this is

OR
Mode C
For first origin name, no matter what this is, rename with first line from list file, no matter what this is
If origin name changes, no matter to what,  increase counter and rename with second line from list file, no matter what this is
If origin name changes again,  increase counter and rename with third line from list file, no matter what this is




2.)
Mode A
Keep the numbering from the last few digits from original file name

OR
Mode B
Add a new numbering for each file with same name



3.)
Add the end, we add fixed ".jpg" with our script.


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

#9 2013-05-24 07:27

bhadkow
Member
Registered: 2013-05-22
Posts: 5

Re: Extension + RegEx + UserInput

bulls eye.  Stefan wink

1) Mode C.
2) Mode A or Mode B. Since, the end result is same in both cases. I don't know which is simpler.
3) Yes. 

P.S. If its not too much trouble,  can we also try 1) Mode A , Mode B?? For fun, learning purposes.

Last edited by bhadkow (2013-05-24 07:27)

Offline

#10 2013-05-24 21:29

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

Re: Extension + RegEx + UserInput

First we start with Mode 'C'

Rename from text file, Mode C:
Rename all files with same pattern with the name found on first line in list file.
Rename next group with next line if the name pattern has changed.



bhadkow wrote:

sample files list before renaming... (9 files)

watermark@&lid=1002856570-I00001
watermark@&lid=1002856570-I00002
watermark@&lid=1002856570-I00003
watermark@&lid=1003516165-I00001
watermark@&lid=1003516165-I00002
watermark@&lid=1043157131-I00001
watermark@&lid=1043157131-I00002
watermark@&lid=1043157131-I00003
watermark@&lid=1043157131-I00004

actual names in names.txt (line by line - 3 lines)
Book One
Book Two
Book Three

final names of the files after working with renamer should be.

Book One 01.jpg
Book One 02.jpg
Book One 03.jpg
Book Two 01.jpg
Book Two 02.jpg
Book Three 01.jpg
Book Three 02.jpg
Book Three 03.jpg
Book Three 04.jpg

(Great kind of providing example file names. Well done!)


Try this PascalScript:
(see our wiki for a how-to >>> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript)

{
Description
   Rename from text file, Mode C.

   Rename all files with same pattern 
   with the name found on first line in list file.
   Rename next group with next line
   if the name pattern has changed.

Note:
   Four slashes //// marks an comment.
   Two slashes // are comments too, but used 
   to comment-out parts of alternative code.
}

var
  iLine, iSerial, iPosEqual, iPosHyphen         : Integer;
  sListFile, sLine, sSerial, CurrName, LastName : WideString;
  bUserSettings                                 : Boolean;
 
begin
  ////// U s e r  S e t t i n g s / / / / / / / / / / / 
  if (not bUserSettings) then
  begin
     ////Use this file as list file:
        //// list file in ReNamer folder
         sListFile := 'NewFilenamesList.txt';
       //// list file in C:\Temp\
       //sListFile := 'C:\Temp\NewFilenamesList.txt';
      
     ////Start at first with reading line n:
        iLine := 0;  //0 is actual line 1.
       
     ////Do this initializing only once: 
     bUserSettings := true;
  end;


  ////// T h e  c o d e / / / / / / / / / / / / / / / / 
  ////Get parts of filename as identifier pattern////
  ////Example "watermark@&lid=1002856570-I00001"
  ////Just get 10 signs, start at sign 16:
    //CurrName  := WideCopy(FileName,16,10); //here: "1002856570"
  ////Alternatively serach for "=" and "-":
     iPosEqual  := WidePos( '=' , FileName );
     iPosHyphen := WidePos( '-' , FileName );
     CurrName   := WideCopy(FileName,iPosEqual+1,iPosHyphen-iPosEqual);      
  ////Read one line from list file              ////
  ////Increase counter to read next line only on file name change:
     if(CurrName <> LastName) then iLine := iLine + 1;


  ////Read now the wanted line into var:
     sLine     := FileReadLine(sListFile, iLine);
  ////Error handling, if no line can be read (any more):
    //if(sLine='')then Exit; //means: skip this file
  ////Alternatively, use this string as new name to see what happens:
      if(sLine='')then sLine := '_E R R O R  no more lines in list ######';

  ////Add an own numbering, serializing, with padding to width 4////
  ////To start numbering with 1 use a '0', to start with 0 use '-1'
     if(CurrName <> LastName) then iSerial := 0;
     iSerial  := iSerial + 1;
     sSerial  := IntToStr(iSerial);
     while Length(sSerial) < 4 do
           sSerial := '0'+sSerial;
  ////Alternatively, extract the origin numbering WideCopy().
  
  ////Store current name as now last name to track name changes////
     LastName := CurrName;
          
  ////Compose new file name with extracted line, new serial and add an extension////
     FileName := sLine + ' ' + sSerial + '.jpg';
end.



big_smile big_smile big_smile  If that helps somebody, then please donate to Denis. Or help four others too yourself in the next 30 days big_smile big_smile 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

Board footer

Powered by FluxBB