You are not logged in.
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
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
Or even simpler...
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
Question:
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?
---
Solved:
1800+ files were renamed in a matter of seconds. approximately 30 directories.
Last edited by Stefan (2010-06-29 07:52)
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
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
Teknik, can you supply example file/folder names, including their presumable unencrypted names?
Offline
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
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
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
I love your short and effective scripts ::thumpsup::
Thanks for sharing! *metrytolearn*
.
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