#1 2006-06-30 01:59

wishlish
Member
Registered: 2006-06-30
Posts: 5

Question about changing numbers in file names

I get a batch of files with numbers at the end- some will be name 1, some othername 02, and others yetanothername 003. I want to standardize the numbers so that they're all 3 digits long- name 001, othername 002, yetanothername 003. Any thoughts on how to do this?

Offline

#2 2006-06-30 08:53

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

Re: Question about changing numbers in file names

Here are the steps to achieve that:
1) Add you files;
2) Right-click the table column and select "Name Digits" from the menu;
3) Click on the new "Name Digits" column to sort files by numbers in their names;
4) Add Strip rule to strip Digits from the filename;
5) Add Serialize rule, Incremental start 1 step 1, pad to length 3, at suffix;

Done! Here is a screenshot how it should look like before renaming:
renum8nn.jpg

Good luck smile

Offline

#3 2006-07-01 02:38

wishlish
Member
Registered: 2006-06-30
Posts: 5

Re: Question about changing numbers in file names

But I don't want to strip the numbers. The numbers may not be in order, but I still want them; think file 474, fileb 30, etc. Would that still work?

Offline

#4 2006-07-02 23:22

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

Re: Question about changing numbers in file names

I'm not really sure what you are trying to do... can you explain it in more details? You could use export/import feature to show me a list of files, or a screenshot perhaps, but do explain what you are trying to do, giving examples of all different variations.

I can't help you if I don't know what you trying to achieve wink

Offline

#5 2006-07-03 13:48

wishlish
Member
Registered: 2006-06-30
Posts: 5

Re: Question about changing numbers in file names

Here goes:

I get a bunch of files twice a week. Each has a different name and a number in the title. They're digital comics, so I get:

Spider-Man 26
Hulk 434
Batman 2

etc. The numbers are not sequential in any way.

I want, when I'm done, for the files to look like this:

Spider-Man 026
Hulk 434
Batman 002

I want to keep the value of the number, just format it into a three-digit number with leading zeroes.

Does that make more sense?

One other thing- sometimes there are other numbers in the title. I don't want to change those other numbers. So I might get:

Spectacular Spider-Man v2 12

I don't want

Spectacular Spider-Man v002 012

but rather

Spectacular Spider-Man v2 012.

The number I want to format will always be the last number, and will always be at the end of the filename.

Offline

#6 2006-07-05 14:07

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

Re: Question about changing numbers in file names

Use this code in PascalScript rule:

var
  BaseName, Extension: string;
  EndDigitsCount, I: Integer;

const
  PAD_TO_LENGTH = 3;

procedure Inc(var A: Integer);
begin
  A := A + 1;
end;

begin
  EndDigitsCount := 0;
  BaseName := WideToAnsi(WideExtractBaseName(FileName));
  Extension := WideToAnsi(WideExtractFileExt(FileName));
  for I:=Length(BaseName) downto 1 do
    if IsWideCharDigit(BaseName[i])
      then Inc(EndDigitsCount)
      else Break;
  if (EndDigitsCount > 0) and (EndDigitsCount <= PAD_TO_LENGTH) then
    while EndDigitsCount < PAD_TO_LENGTH do
      begin
      Insert('0', BaseName, I+1);
      Inc(EndDigitsCount);
      end;
  FileName := AnsiToWide(BaseName + Extension);
end.

I tried it on you examples:
Batman 2.txt
Hulk 434.txt
Spectacular Spider-Man v2 12.txt
Spider-Man 26.txt

And here is what comes out:
Batman 002.txt
Hulk 434.txt
Spectacular Spider-Man v2 012.txt
Spider-Man 026.txt

Just the way you wanted, I think smile

Offline

#7 2006-07-06 02:07

wishlish
Member
Registered: 2006-06-30
Posts: 5

Re: Question about changing numbers in file names

Yep, worked smooth as silk. Thanks for the help! Is there a PayPal address I can donate to? This program's awesome.

Offline

#8 2006-07-06 15:59

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

Re: Question about changing numbers in file names

You are welcome! No, I don't have a PayPal account... so just enjoy using it, and spread the word big_smile

Offline

#9 2006-07-06 23:08

wishlish
Member
Registered: 2006-06-30
Posts: 5

Re: Question about changing numbers in file names

I will- thanks!

Offline

#10 2006-07-06 23:28

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Question about changing numbers in file names

Hi Dennis, i've got a quick question for you regarding the pascalscript you posted above

You have these lines

var
  BaseName, Extension: string;
  EndDigitsCount, I: Integer;

........................

  BaseName := WideToAnsi(WideExtractBaseName(FileName));
  Extension := WideToAnsi(WideExtractFileExt(FileName));
  for I:=Length(BaseName) downto 1 do
    if IsWideCharDigit(BaseName[I])
      then Inc(EndDigitsCount)
      else Break;

After
BaseName := WideToAnsi(WideExtractBaseName(FileName));
BaseName should be the ANSI version of the unicode filename minus the extension

But then you use
   if IsWideCharDigit(BaseName[I])
Shouldn't that return false as BaseName has already been converted to ANSI ?

I don't get it
Im not sure why the double checks are inplace, especially when I'd assume that any variety of IsWide should fail on a normal string?

I'm missing something :conf:

Offline

Board footer

Powered by FluxBB