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::$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
Comprimere file e cartelle con PowerShell senza usare altri strumenti | IlSoftware.it

Comprimere file e cartelle con PowerShell senza usare altri strumenti

Come comprimere file in Windows usando PowerShell: i comandi da usare al prompt oppure all'interno di uno script. C'è anche la possibilità di regolare il livello di compressione e aggiornare il contenuto dell'archivio Zip.

Com’è noto, Windows integra in Esplora file la possibilità di creare e aprire archivi compressi in formato Zip (altri formati non sono al momento supportati).
Meno conosciuto è invece lo strumento di compressione offerto da Windows PowerShell: da riga di comando o mediante uno script si possono aggiungere file in un archivio compresso rendendo la procedura di creazione degli elementi Zip ancora più veloce. PowerShell, tra l’altro, consente anche di definire il livello di compressione da applicare sui dati in modo da rendere gli archivi compressi ancora più compatti.

I comandi PowerShell da utilizzare (si chiamano cmdlet) sono molto semplici.

Usando la sintassi seguente, per esempio, si chiederà a PowerShell di comprimere tutto il contenuto della cartella C:\TEMP (file ed eventuali sottocartelle) memorizzandolo in un file chiamato D:\ARCHIVIO.zip:

Compress-Archive -Path C:\TEMP\* -CompressionLevel Optimal -DestinationPath D:\ARCHIVIO.zip

Avendo specificato Optimal, la creazione dell’archivio Zip richiederà più tempo ma tutti i file saranno compressi il più possibile in modo da occupare il minore quantitativo di spazio.

Al posto di Optimal si può indicare eventualmente Fastest: in questo caso la compressione dei dati sarà molto più veloce ma l’archivio avrà dimensioni maggiori.
C’è anche l’opzione NoCompression che trasforma il file Zip in un semplice contenitore (non verrà applicata alcuna compressione ai file e al loro contenuto).

Nel caso in cui si volesse successivamente aggiornare in automatico il contenuto dello stesso file compresso D:\ARCHIVIO.zip inserendovi tutte le modifiche apportate al contenuto della cartella specificata, basterà digitare quanto segue:

Compress-Archive -Path C:\TEMP -Update -DestinationPath D:\ARCHIVIO.zip

Infine, per richiedere la decompressione dei file da PowerShell, è sufficiente digitare quanto segue:

Expand-Archive -Path D:\ARCHIVIO.zip -DestinationPath C:\DESTINAZIONE

Al posto dei percorsi indicati, ovviamente, bisognerà aver cura di inserire quelli corretti.

Ti consigliamo anche

Link copiato negli appunti