Need help in deleting folders

hello,

I am trying to delete files and folders from specific directory like entire $item (including the folder and its subcontents) has to be deleted from $workingFolderPath

>  Get-ChildItem -Path "$WorkingFolderPath" -Directory -Filter "$item" -Verbose 4>&1 | Remove-Item -Recurse -Confirm:$false -Force -ea SilentlyContinue -Verbose 4>&1|Out-File -Append "$LogPath\log.txt"

Eg:

D:\Workingfolder\abcdefg.upm_2020-07-01_16.17.58\UPM_Profile\AppData\Local\Microsoft\Windows\AppCache\0X0SYCQF\1\precompiled-default~addon-graph-deferredoperations~channel-files~external-files~personal-files~recent-files~spad~0037f0bc.min.c9c856d1cb32abc8[1].js

$workingfolderpath is d:\workingfolderpath ; $item is abcdefg.upm_2020-07-01_16.17.58

I was able to view these files when I uncheck the option " Hide protected os files" from folder options.

Could you please suggest mea way to delete such folder containing long tree or long path.
Also please help me to log the verbose operations from the above command. I am unable to log them.

your help is much appreciated. Thanks in advance

Could you please format your code as code here in the forum? Thanks in advance.

Didn’t we already solve this problem a few days ago?

To delete a folder with its files and subfolders that’s all you need:

Remove-Item -Path 'Full Path Of The Folder To Delete' -Recurse -Force

If you have problems deleting files with paths longer than 260 charachters you should activate the “long path support”.

1 Like