简体   繁体   中英

How to delete a folder in windows with PowerShell?

I have a folder in windows that's name is RESIDENCES INC. . The problem is this is actually an invalid foldername because of the period in it. If I try to delete it, it says

Could not find this item. This is no longer located in <path to folder>. Verify the item's location and try again.

How can I remove it with code?

That's weird, might be a Windows thing? It worked fine for me:

PS /home/Documents/test> mkdir "RESIDENCES INC."

PS /home/Documents/test> gi './RESIDENCES INC./'


    Directory: /home/Documents/test

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           3/18/2021 12:04 AM                RESIDENCES INC.

PS /home/Documents/test> (gi './RESIDENCES INC./').FullName
/home/Documents/test/RESIDENCES INC./

PS /home/Documents/test> Remove-Item (gi './RESIDENCES INC./').FullName -Force

PS /home/Documents/test> (gi './RESIDENCES INC./').FullName                   

Get-Item: Cannot find path '/home/Documents/test/RESIDENCES INC./' because it does not exist.
PS /home/Documents/test> 

Can you paste the command you're using to delete the folder?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM