0

Would like to use powershell to loop through all C:\Users\* and delete all contents of a subdirectory...
Some users, but not all, use an app that creates cache files at: C:\Users\UserName\AppData\Local\SomeApplication\CacheFiles

I'm just not sure how to use /*/ to go to all the user dirs and continue if the CacheFiles directory doesn't exist or if it's empty... Do we need to get all C:\Users\ store it in an array and then pass that plus the rest of the path? Or Can we simply just say for all "Dirs" in C:\Users\* delete rest of path...?

I don't know if I'm making this harder than it needs to be...this is what I have:

Get-ChildItem -Path C:\Users\*\AppData\Local\SomeApplication\CacheFiles -Include *.* -File -Recurse | foreach { $_.Delete()}

3
  • 1
    so ... what is not working? that looks like it would get all the files in the designated dir for all your users.
    – Lee_Dailey
    Commented Apr 27, 2022 at 0:04
  • Yes, it actually did work!
    – AM_Hawk
    Commented Apr 27, 2022 at 1:15
  • kool! glad to know your code worked as needed ... [grin]
    – Lee_Dailey
    Commented Apr 27, 2022 at 3:07

0

You must log in to answer this question.

Browse other questions tagged .