1

У меня есть сотни папок на диске A, которые я хочу перенести на диск B. В корне диска B я хочу, чтобы папки с диска A помещались в папки, каждая из которых содержит по 100 папок. Как это можно сделать в Windows?

1 ответ1

2

Вот немного PowerShell ...

[string]$source = "C:\Source Folder"
[string]$dest = "C:\Destination Folder"

# Number of folders in each group.
[int]$foldersPerGroup = 100

# Keeps track of how many folders have been moved to the current group.
[int]$movedFolderCount = 0

# The current group.
[int]$groupNumber = 1

# While there are directories in the source directory...
while ([System.IO.Directory]::GetDirectories($source).Length -gt 0)
{
    # Create the group folder. The folder will be named "Group " plus the group number,
    # padded with zeroes to be four (4) characters long.
    [string]$destPath = (Join-Path $dest ("Group " + ([string]::Format("{0}", $groupNumber)).PadLeft(4, '0')))
    if (!(Test-Path $destPath))
    {
        New-Item -Path $destPath -Type Directory | Out-Null
    }

    # Get the path of the folder to be moved.
    [string]$folderToMove = ([System.IO.Directory]::GetDirectories($source)[0])

    # Add the name of the folder to be moved to the destination path.
    $destPath = Join-Path $destPath ([System.IO.Path]::GetFileName($folderToMove))

    # Move the source folder to its new destination.
    [System.IO.Directory]::Move($folderToMove, $destPath)

    # If we have moved the desired number of folders, reset the counter
    # and increase the group number.
    $movedFolderCount++
    if ($movedFolderCount -ge $foldersPerGroup)
    {
        $movedFolderCount = 0
        $groupNumber++
    }
}

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .