#1 2009-04-21 13:30

will2kill
Member
Registered: 2009-04-21
Posts: 1

Name Reversing Script

If anyone knows of a way to write a script that reverses the file name of a file except the extension (holding the extension isn't paramount but I'd prefer it). Maybe even make it reverse a certain range of a file name.

I hope someone will be able to help,
Thanks in advance.

Offline

#2 2009-04-21 17:55

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: Name Reversing Script

I'm not sure if that's what you need. But you can try it.
It reverses whole filename without ext. I don't know what you mean by certain range (from beggining to the 10th char? from position 5 till 10? from word "foo" till the end?).

var
Temp, BaseFilename : WideString;

i,k : Integer;

begin

  BaseFilename:=WideExtractBaseName(FileName);
  Temp:=''; 
  i:=1;
  for k:=Length(BaseFilename) downto 1 do
    begin
      WideInsert(WideCopy(BaseFilename,k,1), Temp, i);  
      i:=i+1;
    end;
  
  FileName:=Temp + WideExtractFileExt(FileName);
end.

If it's not that you need to be more specific. Especially real examples are welcome.


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#3 2009-04-21 23:31

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

Re: Name Reversing Script

Or even simpler... smile

var
  I, Count: Integer;
  Temp: WideString;
begin
  Temp := WideExtractBaseName(FileName);
  Count := Length(Temp);
  for I := 1 to Count do
    FileName[i] := Temp[Count - I + 1];
end.

Offline

#4 2010-06-26 14:53

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

Re: Name Reversing Script

Question:

ScottS wrote:

The original problem was caused by a utility called "Folder Lock" which is an encryption program
that locks up a certain file folder and opens it upon entry of password.
Somehow the file got messed up and when it was opened next, thousands of files were misnamed.
Fortunately they all had the same mis-naming pattern, which was reversal of the filename completely,
and 3 characters as a prefix.

For example:
Windowshurts.jpg
was "encrypted" to
s~#gpj.struhswodniW

How can i rename them back?


---


Answer:
To repair the filename for good
FROM:
s~#gpj.struhswodniW
s~#gpj.retsneF seualB
s~#gpj.muartnetülB
s~#pmb.ellydI enürG
s~#fdp.launaM tpircS lacsaP
s~#fdp.ediuG kciuQ
s~#fdp.launaM resU
TO:
Windowshurts.jpg
Blaues Fenster.jpg
Blütentraum.jpg
Grüne Idylle.bmp
Pascal Script Manual.pdf
Quick Guide.pdf
User Manual.pdf

you can do this with den4b ReNamer by using an PascalScript Rule

Here is the script:

var
  I: Integer;
  new: WideString;
  
begin

 //--- FileName example: s~#gpj.struhswodniW
 //-------------------------------------------------


 //Revers the string:
 For I:=1 to Length(FileName) do
     new := FileName[i] + new;

 //--- new example: Windowshurts.jpg#~s
 //-------------------------------------------------


 //remove last 3 signs, the trailing '#~s'
 Delete( new , Length( new )-2 , 3 );

 //--- FileName example:  Windowshurts.jpg
 //-------------------------------------------------


 //set the FileName to what is stored in var new:
 FileName := new;
 //------------------------------------------------- 

 //emtpy 'new' for the next filename
 new :=''

end.

Or in short:

var
  Char: Integer; NewName: WideString;  
begin
 For Char := 1 to Length(FileName) do
     NewName := FileName[Char] + NewName;
 Delete( NewName , Length( NewName )-2 , 3 );
 FileName := NewName; NewName  :='';
end.

See the wiki how to do this: http://www.den4b.com/wiki/ReNamer:Rules:PascalScript
See the WIKI for more about using Rules: http://www.den4b.com/wiki/ReNamer:Rules


HTH?  smile

---

Solved:

ScottS wrote:

1800+ files were renamed in a matter of seconds. approximately 30 directories.

Last edited by Stefan (2010-06-29 07:52)


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#5 2011-02-17 20:23

Teknik
Member
Registered: 2011-02-17
Posts: 4

Re: Name Reversing Script

Sorry for the necropost but I have the same problem as the OP. I tried your method and it just didn't work. My problem was also caused by folder lock. I have a few folders which are renamed in reverse order but most folders have ''s~#'' in the beginning of their name. I used the renamer to try and remove this string of letters but it didn't work. Not only that, Windows doesn't recognize my file extensions anymore because of the name scramble folder lock caused. What can I do?

Offline

#6 2011-02-17 20:53

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

Re: Name Reversing Script

Teknik, can you supply example file/folder names, including their presumable unencrypted names?

Offline

#7 2011-02-17 20:55

Teknik
Member
Registered: 2011-02-17
Posts: 4

Re: Name Reversing Script

Yeah. Like this:

''s~#Unknown#~s''

was formerly this:

''Unknown''

Other times the names are reversed. Like that:

''s~#sartxE''

used to be that:

''Extras''

I have to specify, I already tried using PascalScript and the ''Remove feature'' so it may conflict if I try to do it again.

Last edited by Teknik (2011-02-17 20:57)

Offline

#8 2011-02-17 21:06

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

Re: Name Reversing Script

Filename "s~#Unknown#~s" doesn't seem to be encrypted at all, if the true name is "Unknown". In this case you only need to remove everything from sides up to # character, which can be done using the Delete rule.

Filename "s~#sartxE" will require usage of a script (below), to invert the name, which will give you "Extras#~s". Then, you can use Delete rule to delete everything after the # character.

var
  I, Count: Integer;
  Temp: WideString;
begin
  Temp := FileName;
  Count := Length(Temp);
  for I := 1 to Count do
    FileName[i] := Temp[Count - I + 1];
end.

Offline

#9 2011-02-17 21:31

Teknik
Member
Registered: 2011-02-17
Posts: 4

Re: Name Reversing Script

Alright, thank you. I will try using the ''Delete'' rule for now. Question though, what's that ''position'' and ''count'' thing on the delete rule? Since I tried the remove and delete rule already, the paths conflict and I can't rename, what should I do?

Last edited by Teknik (2011-02-17 21:35)

Offline

#10 2011-02-17 21:35

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

Re: Name Reversing Script

I love your short and effective scripts ::thumpsup::

Thanks for sharing! *metrytolearn*


.


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

Board footer

Powered by FluxBB