Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8087

Профиль | Отправить PM | Цитировать


На PowerShell:
Скрытый текст
Код: Выделить весь код
Param (
    [System.String]$sSourceFolder   = "c:\new",
    [System.String]$sRootDestFolder = "c:\new"
)

if([System.IO.Directory]::Exists($sSourceFolder)) {
    if([System.IO.Directory]::Exists($sRootDestFolder)) {
        Get-ChildItem -Path $sSourceFolder -File | ForEach-Object -Process {
            if([System.Text.RegularExpressions.Regex]::IsMatch($_.Name, '^x\d+_000000\d{8}\d+_\d+\.mp4$', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)) {
                $oMatch = [System.Text.RegularExpressions.Regex]::Match($_.Name, '^(x\d+)_000000(\d{8})\d+_\d+(\.mp4)$', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)

                if($oMatch.Success) {
                    $sDestFolder = "$sRootDestFolder\$($oMatch.Groups[1].Value)\$($oMatch.Groups[2].Value)"

                    if(-not [System.IO.Directory]::Exists($sDestFolder)) {
                        [System.IO.Directory]::CreateDirectory($sDestFolder) | Out-Null
                    }

                    if(-not [System.IO.File]::Exists("$sDestFolder\$($_.Name)")) {
                        Write-Host "Moving source file [$($_.FullName)] into [$sDestFolder]." -ForegroundColor Cyan
                        $_.MoveTo("$sDestFolder\$($_.Name)")
                    } else {
                        Write-Host "Can't move source file [$($_.FullName)], because destination file [$sDestFolder\$($_.Name)] already exists." -ForegroundColor Cyan
                    }
                } else {
                    Write-Host "Strange error for regular expression :)." -ForegroundColor Red
                }
            } else {
                Write-Host "Found other file [$($_.Name)] in source folder." -ForegroundColor Cyan
            }
        }
    } else {
        Write-Host "Can't find destination folder [$sDestFolder]." -ForegroundColor Red
    }
} else {
    Write-Host "Can't find source folder [$sSourceFolder]." -ForegroundColor Red
}

В примере целевой каталог совпадает с исходным.
Это сообщение посчитали полезным следующие участники:

Отправлено: 14:44, 07-08-2018 | #2