#1 2012-11-21 08:35

Rusherman
Member
Registered: 2011-06-02
Posts: 8

How to Delete Date from file name

I want to delete the date from some of my file names as in
file 2003 name.ext To read file name.ext.
I don't think there is any wild card just for numbers which would help me here.
Can anyone give me a hand pointing in the right direction on this please?

Offline

#2 2012-11-21 10:46

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

Re: How to Delete Date from file name

For your example

FROM:
file 2003 name.ext
TO:
file name.ext

you can use "Strip" and "CleanUp" rules.


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 2012-11-21 18:52

Rusherman
Member
Registered: 2011-06-02
Posts: 8

Re: How to Delete Date from file name

Thank you Stefan. I was so locked into wild cards that I never considered the strip command. I hate to keep bothering you but how would I have it strip only groups of four digits. There may be other numbers that I want to keep in that are less than four digits.

Offline

#4 2012-11-21 20:44

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

Re: How to Delete Date from file name

Rusherman wrote:

how would I have it strip only groups of four digits.
There may be other numbers that I want to keep in that are less than four digits.

That depends on your file names. You have to find an common pattern.
Without real world examples i have no glue.

The simplest one is an regular expression like
Express: (.*) (\d\d\d\d) (.*)
Replace: $1 $3

but if that works correct for all files depends on the name pattern of that files.

f.ex. this above works only for
file 1234 name.txt
but not for
1234 name.txt
file 1234.txt

To work more universal i would try an PascalScript which can test for all three possibles at ones:

var
  Parts: TStringsArray;
  Base, Exte: WideString;
  
begin
  Base := WideExtractBaseName(FileName);
  Exte := WideExtractFileExt(FileName);

  //try for file 1234 name.txt  
  Parts := SubMatchesRegEx(Base, '(.+)( \d\d\d\d)(.+)', FALSE);
  If (Length(Parts) = 3)Then
  begin
    FileName := Parts[0] + Parts[2] + Exte;
    Exit;
  End;
  
  //try for 1234 name.txt
  Parts := SubMatchesRegEx(Base, '(\d\d\d\d )(.+)', FALSE);
  If (Length(Parts) = 2)Then
  begin
    FileName := Parts[1] + Exte;
    Exit;
  End;
  
  //try for file 1234.txt
  Parts := SubMatchesRegEx(Base, '(.+)( \d\d\d\d)', FALSE);
  If (Length(Parts) = 2)Then
  begin
    FileName := Parts[0] + Exte;
    Exit;
  End;
end.

See our wiki for an how-to work with PascalScript rules.


.


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 2012-11-22 00:31

Rusherman
Member
Registered: 2011-06-02
Posts: 8

Re: How to Delete Date from file name

Thank you again Stefan. The Pascalscript, along with strip command being run before it does the trick quite nicely. It takes out the date and leaves my series numbers untouched.

Last edited by Rusherman (2012-11-22 05:50)

Offline

Board footer

Powered by FluxBB