You are not logged in.
Pages: 1
Is there a way to read text from the the contents of a file, then grab a string from the file, then use that string in renaming of the file?
Say that 'article_Title_3.15.2005.txt' contains the string '<title>Renamer Tool Speeds Productivity</title>' somewhere in the file.
Could I write a script that would search the file for that (title) string, then rename the file to 'article_'Renamer Tool Speeds Productivity_3.15.2005.txt'?
Hope this makes sense. Thanks in advance. The software is of great help for me!
Offline
Yes, it is possible! Are you familiar with PascalScript rule or Delphi/Pascal programming language at all?
If not, then describe all the variations of your files and what exactly you want to read from them and where exactly you want to paste whatever you read from them. Give as much description as you can, preferably with examples. I can write a script for you
Offline
Hi Denis!
Fantastic program!!
I also need this same functionality, I need to search a text file for a string and then rename the file using that string.
I have some programming experience, but am unfamiliar with the syntax of PascalScript, is there any way you could post an example of how to do this?
Many thanks in advance!
Keep up the good work
Offline
Hi luminos, and thanks
There are sample scripts in the PascalScript rule configurations, find a button called "Scripts", and in the dropdown menu you'll get few examples, including the one to read a text file line-by-line. The syntax of the PascalScript is the same as Pascal or Delphi. Just search the net for Delphi codes and examples, you'll get looooods of results. And here is a good site to start from http://www.delphibasics.co.uk/.
If you are stack, just tell me what you are trying to do (with examples), and I'll write a script for you!
Offline
Hi den4b. This programm is a masterpiece.
I have the same question: need to do this
1. Get the list of selected (for renaming) filenames.
2. Write this list into array.
3. Read the first line from every file in queue into some variable, then use this variable as this file's name.
Like this:
begin
I := I + 1;
FileName := FileReadLine ( FileNamesArray[i], 1);
end.
I don't know how to put list of selected files into array.
And I'm not very familiar with the PascalScript, sorry
English isn't my native language (which is Russian) so excuse me for it ^_^
Last edited by Circumflex (2007-07-06 14:08)
Offline
OMG, it's so easy and I've found it in help
var
I: Integer;
NewName: WideString;
begin
I := I+1;
NewName := FileReadLine(FilePath, 1);
FileName := NewName;
end.
Thanks anyway, I've renamed ALL of my downloaded from lib.ru book collection.
Excellent work!
Offline
You actually need only that much:
begin
FileName := FileReadLine(FilePath, 1);
end.
By the way, Im Russian too!
Offline
...
3. Read the first line from every file in queue into some variable, then use this variable as this file's name.
...
My first pascal script.
I have tried to solve this challenge too:
// take a line from every file 'Name' and use this as 'New Name' for this same file
// f.ex.: file 'Name' "some.txt" contain line "Version 1.2" and so 'New Name' will be "Version 1.2.txt"
// 01 Nov. 2007 by Stefan
const
LineNumber = 1; //which line to choose from file content? The first line? The second? Or the third?
NewNameLenght = 20; // how long should the 'New Name' be? Choose between 1 and 100 only. This line has f.ex. 122 chars.
InValidCharsReplacement = ''; //replace invalid chars in 'New Name' with this char For nothing use ''
NoContentFoundString = 'No Content Found'; // like to know that no content is found? For nothing use ''
var
OldName : WideString;
OldExt : String;
NewName : WideString;
count : Integer;
begin
//Show an message only once:
If count < 1 Then
ShowMessage('Please exclude binary files from extracting lines!'+#13#10+'Otherwise you could get messy file names.')
Count := 1
//store the original file name
OldName := WideExtractBaseName(FileName)
//store the extension of the file name
OldExt := WideExtractFileExt(FileName)
// catch the line number x from the file 'Name'
NewName := FileReadLine(FilePath, LineNumber);
// clean up the NewName by replacing invalid chars \ / : * ? " < > |
NewName := WideReplaceStr(NewName, '\', InValidCharsReplacement);
NewName := WideReplaceStr(NewName, '/', InValidCharsReplacement);
NewName := WideReplaceStr(NewName, ':', InValidCharsReplacement);
NewName := WideReplaceStr(NewName, '*', InValidCharsReplacement);
NewName := WideReplaceStr(NewName, '?', InValidCharsReplacement);
NewName := WideReplaceStr(NewName, '"', InValidCharsReplacement);
NewName := WideReplaceStr(NewName, '<', InValidCharsReplacement);
NewName := WideReplaceStr(NewName, '>', InValidCharsReplacement);
NewName := WideReplaceStr(NewName, '|', InValidCharsReplacement);
//shorten the 'NewName' if needed
If Length(NewName) > NewNameLenght then
SetLength(NewName,NewNameLenght);
//do you want to know that there is no content found? Then the 'New Name' will become an message:
If Length(NewName) < 1 Then
NewName := NoContentFoundString
/////////////////////////////////////////////////////
// Generate the output 'New Name' as you want him.
// Uncomment only one of the following examples:
// Set 'New Name' to "Line.ext"
FileName := NewName + OldExt
// Set 'New Name' to "OldName (Line).ext"
//FileName := OldName + ' (' + NewName + ')' + OldExt
// Set 'New Name' to "OldName - Line.ext"
//FileName := OldName + ' - ' + NewName + OldExt
// Set 'New Name' to "Line [OldName].ext"
//FileName := NewName + ' [' + OldName + ']' + OldExt
end.
Hope this is from some use for someone.
Thanks to Denis for an great tool!
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
Looks like a lot of code for what it does
I would use a simpler script (below), and to strip the invalid characters I would use standard rules.
Of course, I understand that your script is much more flexible, but mine will be much faster for what it does
var
Line: WideString;
begin
Line := FileReadLine(FilePath, 1);
if Line <> '' then
FileName := Line + WideExtractFileExt(FileName);
end.
Offline
Pages: 1