Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <# There is a folder c:\test that contains multiple files and folders. Create powershell code that deletes only the folders with names that match rar archives located in the same folder c:\test #>
- # Get the list of files and folders in c:\test
- $items = Get-ChildItem -Path "c:\test"
- # Loop through each item
- foreach ($item in $items) {
- # Check if the item is a folder
- if ($item.PSIsContainer) {
- # Get the folder name
- $folderName = $item.Name
- # Check if there is a file with the same name and .rar extension
- $rarFile = "c:\test\" + $folderName + ".rar"
- if (Test-Path -Path $rarFile) {
- # Delete the folder
- Remove-Item -Path $item.FullName -Recurse -Force
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement