Archive more than one million files in one folder

Archive more than one million files located in one folder

Archive more than one million files located in one folder

Windows operating systems are not good candidates to host and manage million files located in only folder (no subfolders). If you try to list the content of the folder (using the GUI Windows File Explorer or the Get-ChildItem Powershell cmdlet), it will take several minutes to get the result.

The mission was to reduce the amount of files in this directory. I have created a script to manage that :

  • list the folder with the dir DOS command and limit to the first 5000 results
  • use 7zip to put them into a zip file named using the “date modified” information of the file : if the file has been modified on the 27.03.2015, it will be archived the zip file called _archive_201503.zip
  • if the zip operation is successful by checking the 7zip result code, the file is deleted
  • only files older than 3 months are archived

All changes are logged into a log file called _archive_yyyy-MM-dd.log

The performance is not impressive but efficient : this script can archive 5000 files in 10 minutes

<>

My Powershell script categories

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social Media Auto Publish Powered By : XYZScripts.com
%d bloggers like this: