Reputation: 87
I'm trying to delete all of the desktop.ini
files in a given directory; namely Documents\Gio
. I've tried del /S desktop.ini
and del /S *.ini
in cmd (admin mode) and get-childitem .\ -include desktop.ini -recurse | foreach ($_) {remove-item $_.fullname}
and get-childitem .\ -include *.ini -recurse | foreach ($_) {remove-item $_.fullname}
in PowerShell (also admin). Neither have worked. What should I do?
The desktop.ini
files contain the following:
[.ShellClassInfo]
InfoTip=This folder is shared online.
IconFile=C:\Program Files\Google\Drive\googledrivesync.exe
IconIndex=12
I move the directory from my Google Drive folder but all the folders still have the shared icons on them. I was trying to change the directory and all it subdirectories and files' ownership to a different account. I tried to do this with Google Drive but only the root directory changed ownership; I can't delete any of the files or directories therein.
Upvotes: 4
Views: 8789
Reputation: 11
This will grab every folder in your home directory, and then search that folder for desktop.ini and delete it. It should be faster than using -recurse because it won't search subfolders. It should finish neatly with no errors
foreach ($file in Get-ChildItem -path \\server\homedrivedirectory) {
Get-ChildItem $file.FullName -Filter desktop.ini -force | remove-item -force -WhatIf
}
This will grab every folder in your home directory, and then create a path for every folder to \server\homedrivedirectory\user\desktop.ini and then delete that file. It should run a little faster as it doesn't have to search each user folder but it will turn up errors for every user folder that doesn't have a desktop.ini
foreach ($_ in Get-ChildItem -path \\server\homedrivedirectory) {
$path = $_.fullname
Remove-Item "$path\desktop.ini" -Force -WhatIf
}
I've left a -whatif so you can see what it would do in your environment without it doing it. If you want it to actually delete the files remove the -whatif
Upvotes: 1
Reputation: 361
I had a similar problem and here is my solution:
Get-Location | Get-ChildItem -Force -Recurse -File -Filter "desktop.ini" | Remove-Item
The first part gets the current active directory.
Get-Location
You could replace it with a path like:
"C:\Users\Chris" | Get-ChildItem -Force -Recurse -File -Filter "desktop.ini" | Remove-Item
The second part gets child items in the path.
Get-ChildItem -Force -Recurse -File -Filter "desktop.ini"
The last part removes the item.
Remove-Item
Adding a -WhatIf for the first run may be safer.
Remove-Item -WhatIf
Upvotes: 3
Reputation: 6632
This is what I used for Windows 2012 server
Create Desktop.ini files
My desktop.ini files were created from running this script which sets default folder options
$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key Hidden 1
Set-ItemProperty $key HideFileExt 0
Set-ItemProperty $key ShowSuperHidden 1
Stop-Process -processname explorer
Remove Desktop.ini files
# Remove from your user desktop
gci "$env:USERPROFILE\Desktop" -filter desktop.ini -force | foreach ($_) {remove-item $_.fullname -force}
# Remove from default desktop
gci "C:\Users\Public\Desktop" -filter desktop.ini -force | foreach ($_) {remove-item $_.fullname -force}
Upvotes: 1
Reputation: 58931
With powershell, you use the Get-ChildItem (alias gci
) cmdlet to retrieve all desktop.ini files and pipe it to Remove-Item (alias rm
):
gci 'C:\YOURPATHTODOCUMENTS\GO' -Filter desktop.ini -Recurse | rm
Upvotes: 0