#1 2014-01-08 17:45

kbeil
Member
Registered: 2014-01-08
Posts: 2

New name based on filetype

Hello,

when renaming files form my camera I have different types of files and would like to handle them based on the extension. For example:

*.jpg should be renamed based on their EXIF creation date
*.mp4 filesshould be renamed based on their file modification date.

Can this be done in one run. I mean without selecting the files first and then running different scripts on them?

Best Regards

Offline

#2 2014-01-08 20:27

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

Re: New name based on filetype

I think yes, by utilizing PascalScript:

http://www.den4b.com/wiki/ReNamer:Rules:PascalScript
http://www.den4b.com/wiki/ReNamer:Pascal_Script
http://www.den4b.com/wiki/ReNamer:Pasca … e_and_Time

Such script will be executed for each file.
Just get the extension on each file and then "IF...THEN" extract the date and create a new file name pattern to rename current file.



 


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 2014-01-09 07:02

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: New name based on filetype

Offline

#4 2014-01-09 11:45

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

Re: New name based on filetype

Sweet, thanks Andrew!

I had now time at my launch break and developed a POC script.  Please test if that works for you.

var
 sExte, sDate: WideString;

begin

  sDate := '1981-01-01 00.00.00';
  sExte := WideExtractFileExt(FilePath);

  if( WideUpperCase(sExte) = '.JPG') then
    begin
     //ShowMessage( 'JPG : : : EXIF - ' + FileName )
     sDate := CalculateMetaTag(FilePath, 'EXIF_Date') // YYYY-MM-DD HH.MM.SS
     sDate := copy(sDate,1, 10);  // YYYY-MM-DD
    end;

  if( WideUpperCase(sExte) = '.MP4') then
    begin
     //ShowMessage( 'MP4 : : : mod date - ' + FileName )
     //sDate :=  FormatDateTime(  'yyyy-mm-dd hh.MM.ss',  FileTimeModified(FilePath) );
     sDate :=  FormatDateTime(  'yyyy-mm-dd',  FileTimeModified(FilePath) );
    end;

  //new file name is sDate + - + old file name:
  FileName := sDate + ' - ' + FileName;
  
end.

If yes, please consider donation to Denis. Thanks


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 2014-01-26 18:56

kbeil
Member
Registered: 2014-01-08
Posts: 2

Re: New name based on filetype

Great. Stefan and Andrew: Thanks a lot. Your code worked almost out the box. I only made some minor modifications since my EXIF data seems to come in a different flavour.
I also use the "fix conflicting new names" option but would like to get rid of the braces and the space (e.g "filename (2)" --> "filename-2"). I achieved that with a second run that with a simple replace/remove action set. Is there a more elegant way to achieve this in one run?

btw: just got myself a Pro license. I like ReNamer smile

var
 sExte, sDate: WideString;

begin

  sDate := '1981-01-01 00.00.00';
  sExte := WideExtractFileExt(FilePath);

  if( WideUpperCase(sExte) = '.JPG') then
    begin
     //ShowMessage( 'JPG : : : EXIF - ' + FileName )
     sDate := CalculateMetaTag(FilePath, 'EXIF_Date') // YYYYMMDD-HHMMSS
     sDate := copy(sDate,1, 15);  // YYYYMMDD-HHMMSS
     FileName := sDate + sExte;
    end;

  if( WideUpperCase(sExte) = '.MOV') then
    begin
     //ShowMessage( 'MP4 : : : mod date - ' + FileName )
     //sDate :=  FormatDateTime(  'yyyy-mm-dd hh.MM.ss',  FileTimeModified(FilePath) );
     sDate :=  FormatDateTime(  'yyyymmdd-hhMMss',  FileTimeModified(FilePath) );
     FileName := sDate+sExte;
    end;

  //new file name is sDate + - + old file name:
  //FileName := sDate + ' - ' + FileName;
  
end.

Offline

#6 2014-01-27 17:21

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

Re: New name based on filetype

kbeil wrote:

I also use the "fix conflicting new names" option but would like to get rid of the braces and the space (e.g "filename (2)" --> "filename-2"). I achieved that with a second run that with a simple replace/remove action set. Is there a more elegant way to achieve this in one run?

You can enable the "Fix conflicting new names" option permanently in the Settings, in Preview tab. This will let you do everything in a single run. There is also another way for doing this, via Pascal Script (bundled "serialize duplicates" script), but using standard rules is more efficient than using scripts.

kbeil wrote:

btw: just got myself a Pro license.

Thanks for your support! big_smile

Offline

Board footer

Powered by FluxBB