Neculai Fântânaru

Everything Depends On The Leader

How To Increment Numbers In Python In Multiple Files

On March 10, 2022
, in
Python Scripts Examples by Neculai Fantanaru

You can view the full code here: https://pastebin.com/2wK5D6hw

Install Python. Then install the following two libraries using the Command Prompt (cmd) interpreter in Windows10:

I have multiple html files in C:Folder1. I have this structure that is repeated in each html files:.

< ! -- $item_id = abc;

After running .py I will get:

In file 1.html I will have $item_id = 1;
In file 2.html I will have $item_id = 2;
In file 3.html I will have $item_id = 3;
...
In file 2300.html I will have $item_id = 2300;

CODE: Copy and run the code below in any interpreter program (I use pyScripter) .Don't forget to change the path in the "incrementare_fisiere_html" line.

import os
import re

def read_text_from_file(file_path):
    """
    Aceasta functie returneaza continutul unui fisier.
    file_path: calea catre fisierul din care vrei sa citesti
    """
    with open(file_path, encoding='utf8') as f:
        text = f.read()
        return text


def write_to_file(text, file_path):
    """
    Aceasta functie scrie un text intr-un fisier.
    text: textul pe care vrei sa il scrii
    file_path: calea catre fisierul in care vrei sa scrii
    """
    with open(file_path, 'wb') as f:
        f.write(text.encode('utf8', 'ignore'))

def incrementare_fisiere_html(cale_folder_html):
    """
    Functia itereaza printr-un folder care contine fisiere html si adauga index-ul corespunzator in fiecare fisier
    """
    count = 0
    current_id = 1
    for f in os.listdir(cale_folder_html):
            if f.endswith('.html'):
                cale_fisier_html = cale_folder_html + "\\" + f
                html_text = read_text_from_file(cale_fisier_html)
                item_id_pattern = re.compile('\


                                
Alatura-te Comunitatii Neculai Fantanaru
The 63 Greatest Qualities of a Leader
Cele 63 de calităţi ale liderului

Why read this book? Because it is critical to optimizing your performance. Because it reveals the main coordinates after that are build the character and skills of the leaders, highlighting what it is important for them to increase their influence.

Leadership - Magic of Mastery
Atingerea maestrului

The essential characteristic of this book in comparison with others on the market in the same domain is that it describes through examples the ideal competences of a leader. I never claimed that it's easy to become a good leader, but if people will...

The Master Touch
Leadership - Magia măiestriei

For some leaders, "leading" resembles more to a chess game, a game of cleverness and perspicacity; for others it means a game of chance, a game they think they can win every time risking and betting everything on a single card.

Leadership Puzzle
Leadership Puzzle

I wrote this book that conjoins in a simple way personal development with leadership, just like a puzzle, where you have to match all the given pieces in order to recompose the general image.

Performance in Leading
Leadership - Pe înţelesul tuturor

The aim of this book is to offer you information through concrete examples and to show you how to obtain the capacity to make others see things from the same angle as you.

Leadership for Dummies
Leadership - Pe înţelesul tuturor

Without considering it a concord, the book is representing the try of an ordinary man - the author - who through simple words, facts and usual examples instills to the ordinary man courage and optimism in his own quest to be his own master and who knows... maybe even a leader.