You are not logged in.
Pages: 1
Hi everyone,
I have a list with names and Numbers. Every Name has a certain Number.
E.G.:
Dave | 115
Marc | 232
and so on. (List would even be available as a .cvs list)
And I have a folder with many files that include the number at a certain point.
e.g. : thisandthat_115_120512.pdf
Evertime there is is a 115 in the FileName I want to add the Prefix 'Dave'.
I used to code it with Pascal from Scratch but don't really get why it doesn't work. I hope somebody can help me.
P.S. I added a Picture of my code.
Last edited by Luro (2019-09-19 12:55)
Offline
Hi and welcome!
LIST:
Dave | 115
Marc | 232
FROM:
thisandthat_115_120512.pdf
thisandthat_232_120512.pdf
TO:
Dave thisandthat_115_120512.pdf
Marc thisandthat_232_120512.pdf
TRY:
Replace Rule
http://www.den4b.com/wiki/ReNamer:Rules:Replace
Replace: Replace using wildcards "*115*" with "Dave $1,115$2" (skip extension)
Replace: Replace using wildcards "*232*" with "Marc $1,232$2" (skip extension)
EXPLANATION:
- - Find first every thing (*) and store for re-use by $1
- - Find literal "115"
- - Find every thing (*) after that and store for re-use by $2
There is a problem by using $1115, so I use $1,115 add a comma. (I think there was a trick, but can't remember)
You can add as last rule a Remove Rule for to remove commas from file name.
EDIT:
silly me
USE:
Replace: Replace using wildcards "*_115_*" with "Dave $1_115_$2" (skip extension)
Replace: Replace using wildcards "*_232_*" with "Marc $1_232_$2" (skip extension)
/EDIT
- - -
You can use the Analyze tool first to test that out. (Use [x] Apply rules for each line)
http://www.den4b.com/wiki/ReNamer:Analyze
- - -
If you want to do that by an PascalScript.... how long is your list? Is it ok to store that list in the PascalScript too?
HTH?
Last edited by Stefan (2019-09-19 12:30)
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
Hi Stefan,
thanks for the very fast answer. It helped me understanding the program. But I don't want to retype this everytime. The problem is that I have a list of about 20-50 names and folders with these Files coming in Monthly. Therefore I wanted to use a switch/case pattern in pascalScript to automise the process. Is it possible to just retype your explanation in pascalscript?
Offline
Hi Luro, check that out if I got it right?
Rename FROM:
thisandthat_115_120512.pdf
thisandthat_232_120512.pdf
TO:
Dave thisandthat_115_120512.pdf
Marc thisandthat_232_120512.pdf
UTILIZING:
"zzzNamesList.txt"
Dave | 115
Marc | 232
TRY:
PascalScript Rule
http://www.den4b.com/wiki/ReNamer:Rules:PascalScript
////PascalScript for den4b ReNamer
////Rename from List with pairs of strings.pas, Stefan 2019-09-19, v00.1
////Found at http://www.den4b.com/forum/viewtopic.php?pid=11046#p11046
//
// Purpose:
// Rename file with part from a list if filename contains an specific string
// Name example: thisandthat_232_120512.pdf
//
// Have a list like here 'zzzNamesList.txt'
// Each line have a pair of one string to add and one string to find, separated by an '|'
// List example line: Marc|232
// (Here used: find 232 and add Marc)
//
// This script extract for each file a wanted part and checks each line of the list for that part.
//
// USER SETTINGS:
// Search the code for "(USER SETTING)"
var
PairList,PartOfName,ArryLine, LinePart1, LinePart2: WideString;
PairListArray,LineParts,RegExSubPatterns: TWideStringArray;
I: Integer;
begin
//Extract namepart of current file.
//Name example: thisandthat_232_120512.pdf (USER SETTING)
//SubMatchesRegEx(const Input, Find: WideString;const CaseSensitive: Boolean): TStringsArray;
RegExSubPatterns:=SubMatchesRegEx(FileName,'(.+?_)(\d\d\d)(_.+)',false);
if Length(RegExSubPatterns) <=0 then exit;
PartOfName := RegExSubPatterns[1];
//showmessage(PartOfName);
//Read list of pairs (USER SETTING):
PairList := FileReadContent('zzzNamesList.txt');
//List example line: Marc|232
//showmessage(PairList);
//Process the list on each file:
PairListArray := WideSplitString(PairList, #13#10);
if Length(PairListArray) < 1 then Exit;
for I:=0 to Length(PairListArray)-1 do
begin
ArryLine := PairListArray[I];
LineParts := WideSplitString(ArryLine, '|');
LinePart1 := LineParts[0]+ ' ' // Marc
LinePart2 := LineParts[1] // 232
//showmessage(LineParts +#13+'1: '+LinePart1+#13+'2: '+LinePart2);
//If namepart and item from list match:
If(PartOfName = LinePart2) Then
begin
// (USER SETTING)
FileName := LinePart1 + FileName;
Break;
end; //match?
end; //PairListArray
end.
HTH?
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
Hi Stefan,
thanks for this big answer. I think I have to work with it a little. Now is my question where do I save the zzzNamesList.txt file?
Offline
H... where do I save the zzzNamesList.txt file?
Where you want, only adjust the path at:
FileReadContent('zzzNamesList.txt');
TXT in ReNamer folder? ...try it:
FileReadContent('zzzNamesList.txt');
TXT in in C:\Temp:
FileReadContent('C:\Temp\zzzNamesList.txt');
TXT in current working directory (not useful for working on several different folder):
FileReadContent(WideGetCurrentDir + 'C:\Temp\zzzNamesList.txt');
See http://www.den4b.com/wiki/ReNamer:Pasca … :Functions
or search the forum with that keywords (or ask us)
- WideGetTempPath
- WideGetEnvironmentVar(var)
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
And I got an idea for performence, read the LIST file only once:
Change:
PairList := FileReadContent('zzzNamesList.txt');
To:
if(GetCurrentFileIndex=1) then
PairList := FileReadContent('zzzNamesList.txt');
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
Ok I will try.
Thank you so much for helping. <3
Offline
Pages: 1