I am working on one of the scenarios, where I have source folder and destination folder.
In Source Folder I have multiple PDF files like
PDF1,PDF2,PDF 3, PDF,4,PDF 5 and more.
Now using for each loop to get one by one PDF files.
And inside loop I have to read pdf and read get accountname.
And after reading file need to move same PDF file with new name like accountname is “PPA” and move this file to destination folder.
now the issue is whenever account name is same in some pdf file so, I have to use count like “PPA1” .
this count is working when acount name has PPA1,PPA2, but when account name is change like PPB,PPB1 than count is adding like PPB2 direct because count is already increase in PPA1 file.
For example:-
Current Folder dest Folder
PDF1 PPA
PDF2 PPA1
PDF3 PPB
PDF4 PPA2
PDF5 PPB1
so in this case count did not add with fresh it is adding with previous one. which is incorrect.
create a Dictionary with string as key(Account) and int as value(count) to store a count for each unique account name (PPA , PPB).
In your loop for each file after read pdf and read get accountname.
Check if key(Account) is present in dictionary if yes increment the count else add key with count as 1.
Per my understanding, one counter variable can not be used in this case.
I dont see any other way to define the name using different counter values without using different counter variables or you can choose to create dictionary like @adi.mehare suggested.
You have account name(PPA), so you can get count of files from destination folder starting with account name(PPA).
From this count you can rename your file accordingly.
You can use below code to get count then increment count and save file.