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

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

Ветеран


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

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


На PowerShell это может выглядеть, например, так:
Скрытый текст
Код: Выделить весь код
$sListFolder   = 'C:\Мои проекты\0235\SomethingLikeThis\LstFldr'
$sSourceFolder = 'C:\Мои проекты\0235\SomethingLikeThis\MainFldr'

if([System.IO.Directory]::Exists($sListFolder)) {
    if([System.IO.Directory]::Exists($sSourceFolder)) {
        $hFiles = @{}
        
        Get-ChildItem -Path $sListFolder -Filter '*.lst' -File |`
            ForEach-Object -Process {
                Write-Host "Reading file name(s) from [$($_.FullName)]…" -ForegroundColor Cyan

                Get-Content -Path $_.FullName |`
                    ForEach-Object -Process {
                        if(-not $hFiles.ContainsKey($_)) {
                            Write-Host "`tAdding unique file name [$_]" -ForegroundColor White
                            $hFiles.Add($_, $_)
                        } else {
                            Write-Host "`tDuplicate file name [$_] found, skipping" -ForegroundColor Gray
                        }
                    }
            }
        Write-Host "Total found $($hFiles.Count) unique file name(s).`r`n" -ForegroundColor Cyan

        if($hFiles.Count -gt 0) {
            Write-Host "Deleting file(s)…" -ForegroundColor Cyan

            Set-Content -Path "Deleted.lst"    -Encoding Default -Value '' -NoNewline
            Set-Content -Path "NonDeleted.lst" -Encoding Default -Value '' -NoNewline

            Get-ChildItem -Path $sSourceFolder -Include $($hFiles.Keys) -File -Recurse -Force |`
                ForEach-Object -Process {
                    $sFullFileName = $_.FullName 

                    Write-Host "`t$sFullFileName" -ForegroundColor White
                    
                    try {
                        $_.Attributes = [System.IO.FileAttributes]::Normal
                        $_.Delete()
                        Add-Content -Path "Deleted.lst" -Encoding Default -Value $sFullFileName
                    } catch {
                        Write-Host "`t`tAn error occured while deleting file [$sFullFileName]" -ForegroundColor Red
                        Add-Content -Path "NonDeleted.lst" -Encoding Default -Value $sFullFileName
                    }
                }
        } else {
            Write-Host "Nothing to delete." -ForegroundColor Cyan
        }
    } else {
        Write-Host "Can't find source folder [$sSourceFolder]." -ForegroundColor Red
    }   
} else {
    Write-Host "Can't find list's folder [$sListFolder]." -ForegroundColor Red
}
Это сообщение посчитали полезным следующие участники:

Отправлено: 07:50, 05-01-2019 | #4