You are reading the article How To Delete Files And Folders Using Windows Powershell updated in September 2023 on the website Nhunghuounewzealand.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How To Delete Files And Folders Using Windows PowershellUse PowerShell to delete files and folders
To delete files and folders using Windows PowerShell, follow these steps-
Open Windows PowerShell
Identify the folder
Use Remove-item command.
Here is the tutorial in detail form.
To get started, you need to open PowerShell. For that, you can press Win+X, and select Windows PowerShell from the list. Alternatively, you can search for it in the Taskbar search box. After that, enter the following command-Remove-item file-path
This is the basic form of the command.
Let’s assume that you have a file named chúng tôi in the TWC folder on your Desktop. To delete it using Windows PowerShell, you need to enter this command-Remove-item C:Usersuser-nameDesktopTWCTWC.png
You have to include the file extension in the command. Otherwise, it won’t recognize your command, and a welcome message will welcome you.
Related: How to delete Files older than X days in Windows
If you want to delete a folder using Windows PowerShell, you need to enter the command as mentioned earlier-Remove-Item folder-path
Let’s assume that you have a folder named TWC on your Desktop. If you want to delete it, you need to enter this command-Remove-item C:Usersuser-nameDesktopTWC
If the folder is empty, it will be deleted immediately. However, if the folder has some files, you need to confirm the delete by pressing Y and Enter buttons.
If you have multiple files to delete, you need to enter a different command. The command looks the same, but there is a small difference.Remove-item file-path, file-path1, file-path2
Like deleting multiple files, the command is the same to remove more than one folder using Windows PowerShell. For example, you can use a command like this-
For your information, if you use these commands, your files and folders will be deleted permanently. In other words, you cannot find them in the Recycle Bin.Check items inside a folder
In case you cannot open a folder, but you want to know about the items, you can use this command-Get-ChildItem folder-path
If you have a folder on your Desktop named TWC, you need to enter the following command to reveal all things-Get-ChildItem C:Usersuser-nameDesktopTWC
By default, it shows the Mode, LastWriteTime, Length, and Name. You can get the file name from here so that you can delete the correct item.Check last modification time and creation time
If you want to check the time when a file was created or modified, you can use this command-
You can find three columns with all the file names and other details.
If your folder has some read-only or hidden files that you want to remove, you cannot use the command mentioned above, as it will show an error. In this case, you have to use the -force parameter. For example, if there are some hidden or read-only files in the TWC folder that is placed on the Desktop, you have to enter this command-Remove-item C:Usersuser-nameDesktopTWC -force
The same command can be used to delete a read-only file, as well. In either case, you will get a confirmation message where you need to type Y and press the Enter button.Delete without confirmation
If you use the very first command of this article, you will be greeted with a confirmation message. However, if you do not want to get such a message, you can use a parameter called -recurse.
For example,Remove-item C:Usersuser-nameDesktopTWC -recurse
After entering this command, your folder or file will be deleted permanently without any confirmation.Exclude certain file type
Let’s assume that you have multiple file types such as TXT, PNG, DOCX, PDF, etc. and you want to delete all items except the TXT files. In that case, you can use the -exclude parameter. The command looks like this-Remove-Item –path C:Usersuser-nameDesktopTWC* -exclude *.txt
You might have already guessed – it will exclude all the .txt files and delete others. However, it shows a confirmation message. If you want to delete them directly, you can use the -recurse parameter as mentioned earlier.
I hope these commands will be helpful for you.
You're reading How To Delete Files And Folders Using Windows Powershell
Update the detailed information about How To Delete Files And Folders Using Windows Powershell on the Nhunghuounewzealand.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!