Элемент удаления Powershell не удаляет файлы - PullRequest
0 голосов
/ 22 апреля 2020

У меня есть скрипт PowerShell 5.1, который должен удалить некоторые файлы. Однако, когда я пытаюсь удалить их, ни del, ни remove-item не работают. Я уже установил политику выполнения к Unrestricted и запустил ISE в режиме администратора. Даже перемещение файла с помощью Move-Item не сработало.

Мой код:

$startROMFolderPath = "C:\Users\VincentGuttmann\Desktop\retropie-mount\roms" #Pleae enter the path to your current ROM folder here, ending in the roms folder. Note that this script will only work if the ROMs are inside the RetroPie folder.
$deleteROMFolder = $startROMFolderPath + "\delete"
Write-Host @"
Hello!
Welcome to my ROM Sorting program!
There are three main ROM types: 
The ROMs that are "known good", which are marked with this tag: [!],
the bad dumps, so "known bad", which are marked [b].
Then there are the ROMs where we don't know.

The ROMs that are known good will be left in the folder.
The bad dumps will be deleted right away, as well as the ROMs which are neither German nor English
If you haven't put in the paths to your current ROM folder, 
please exit the program now by pressing enter and then "n" without quotation marks.
"@

$inputted = Read-Host -Prompt 'Have you changed the paths accordingly? Yes: (y), No: anything else than (y)'

$i = 0

if($inputted -eq "y")
{
  $foldersOld = @()

  Get-ChildItem $startROMFolderPath -Attributes Directory |
  foreach {
    $foldersOld += $_
  }

  foreach ($name in $foldersOld) {
  $currentROMFolderPath = $StartROMFolderPath + "\" + $name
  $ROMList = @()

  Get-ChildItem $currentROMFolderPath -File |
  foreach {
    $currentROMPath = $currentROMFolderPath + "\" + $_
    $containsBad = $_ -match "\[b.\]"
    $containsGood = $_ -match "\[!\]"
    $containsLang = $_ -match ".*(\([UE]+\))|(\(U\).*\(E.*\))|(\(E.*\).*\(U\))|(\(E.*\))|(\([UKNG4A]+\))|(\(Unl\))"

    if($containsBad)
    {
      write-host "====================================="
      Write-Host $_
      Write-Host "contains bad"
      write-host "====================================="
      Remove-Item -Path $currentROMPath -Force
    }
    #Put "!$containsGood -and !$containsLang" into the next bracket if you want to delete all ROMS that are neither good nor in the correct Language.
    #For just keeping ROMs in the corect language, plase use "!$containsLang"
    elseif(!$containsGood -and !$containsLang)
    {
      write-host "====================================="
      Write-Host $_
      Write-Host "Contains no good and no lang"  
      write-host $currentROMPath
      write-host "====================================="
      Remove-Item -Path $currentROMPath -Force
    }
    }
  }
}

else
{
  exit
}

exit
...