0

I am really new to Powershell coding and need your help please

I'm on Windows 10 with Powershell 5.1 and trying to work it out with Winrar. The Main folder contains 5000 subFolders I would like to specify how many folders should be included per archive and compress every X of them as a separate rar files.

create text files and for each rar file a .txt file with all subfoldernames in each rar

For example: first: specify how many folders should be included per archive

the folder name with the 5000 subfolders has the name "Project"

all rar files should have the same name as the main folder with consecutive numbering: in this case

Project - 01.rar
Project - 02.rar
Project - 03.rar
Project - 04.rar
Project - 05.rar
etc....

and for each rar file a txt file which lists the contents of the rar file

Project - 01.txt
Project - 02.txt
Project - 03.txt
Project - 04.txt
Project - 05.txt 
etc...

Is there a way to not do it manually?

webster
  • 11
  • 2

1 Answers1

0

This is my script and it works so far

param
(
    # The input folder containing the files to zip
    [Parameter(Mandatory = $true)]
    [string] $InputFolder,

    # The output folder that will contain the zip files
    [Parameter(Mandatory = $true)]
    [string] $OutputFolder
)

Set-Variable SET_SIZE -option Constant -value 10
$i = 0
$zipSet = 0

Get-ChildItem $InputFolder | ForEach-Object {
    $zipSetName = "archive" + ($zipSet + 1) + ".zip"
    Compress-Archive -Path $_.FullName -Update -DestinationPath "$OutputFolder\$zipSetName"
    $i++;

    if ($i -eq $SET_SIZE) {
        $i = 0;
        $zipSet++;
    }
}

Now I need some help to add the above mentioned options and

  • set Input and Output to Path of currently executing powershell script In a batch file I would do: %~d0%~p0
  • create a folder "Done"in the main folder and move all the Subfolders which have already been added to an archive to "done"
  • always use rar if rar support is given otherwise use zip

thanks

webster
  • 11
  • 2