Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$old_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ext-thumbnail_url is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_lock is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
Modificare più file contemporaneamente: come si fa | IlSoftware.it

Modificare più file contemporaneamente: come si fa

Un semplice espediente, peraltro molto veloce da applicare, che consente di modificare automaticamente un gruppo di file. Il trucco che vi sveliamo poggia sull'utilizzo di Notepad++, uno dei più completi, versatili e apprezzati editor di testo.

Presentiamo uno di quei trucchi che fanno risparmiare ore e ore di lavoro. Se si avesse l’esigenza di modificare il contenuto di più file che condividono una struttura simile è impensabile aprire ogni singolo elemento e intervenirvi manualmente.
L’editor di testo Notepad++ integra uno strumento che permette di esaminare il contenuto di una serie di file per poi effettuare in blocco tutte le modifiche richieste dall’utente.

Ricorrendo alle espressioni regolari (o regular expression), presentate nell’articolo Regular expression o espressioni regolari: cosa sono e come utilizzarle) e utilizzabili in molti programmi (vedere questi articoli) è possibile indicare a Notepad++ di individuare tutti i contenuti che soddisfano criteri di ricerca anche piuttosto complessi.

Il vantaggio derivante dall’utilizzo di Notepad++ è che questo editor di testo opensource (è anche un software libero distribuito sotto licenza GNU GPL) consente di analizzare e modificare direttamente un insieme di file presenti nella cartella specificata. Basta infatti premere la combinazione di tasti CTRL+MAIUSC+F oppure cliccare sul menu Search, Find in Files.

Attivando l’opzione Regular expression e spuntando la casella . matches newline sarà possibile inserire nel campo Find what un’espressione regolare per identificare in maniera univoca la parte o le parti dei file che devono essere modificate.
Abilitando . matches newline il punto sarà considerato come indicatore di una nuova riga all’interno del file di testo.

Un esempio concreto: inserendo in Find what .* tutto quanto compreso tra le tag e verrà automaticamente sostituito con quanto indicato nel successivo campo Replace with.


Nel campo Directory va specificata la cartella contenente i file da modificare mentre in Filters si può ad esempio indicare la tipologia di file sui quali intervenire (ad esempio *.php, *.html, *.eml e così via.

Prima di procedere con qualunque modifica, è bene creare una copia di tutto il contenuto della cartella indicata nel campo Directory tenendo presente che l’utile funzionalità Versioni precedenti può essere attivata anche in Windows 10: Ripristinare versione precedente di un file o di una cartella con Windows 10.

Facendo clic sul pulsante Replace in Files le modifiche saranno immediatamente apportate e tutti i file verranno salvati nella nuova forma. In calce alla finestra, Notepad++ riporta il numero di sostituzioni che sono state applicate.

Consigliamo comunque di cliccare prima sul pulsante Find All in modo da individuare quali file contengono le porzioni di testo che s’intende sostituire automaticamente.

Al posto di e è ovviamente possibile qualunque altra stringa “segnaposto” oppure modificare l’intero contenuto del campo Find what con un’espressione regolare ancora più articolata.

Chicca finale: per rimuovere un’intera riga trovata, è possibile aggiungere \R nella regular expression all’interno del campo Find what.

Ti consigliamo anche

Link copiato negli appunti