How can I delete a non-empty directory using only the allowed commands?

September 26, 2026 3 answers
Asked by !cash drawer count
I'm new to PowerShell and working through a CompTIA lab. I need to delete the directory D:softwarearch98 along with all of its files. When I run rmdir D:softwarearch98, I get an error saying the directory isn't empty. The lab only allows commands such as rmdir, attrib, cd, dir, and mkdir, so I can't use Remove-Item or other commands. What syntax or steps should I use to remove the folder and its contents?

Answers

~!pause for tea
In normal PowerShell, rmdir is an alias for Remove-Item, but deleting a directory that contains files requires the recursive option. The usual command would be Remove-Item -Path "D:softwarearch98" -Recurse -Force. However, if the lab restricts you to rmdir, it may be testing the commandโ€™s recursive option or expecting you to remove the files first. Check the labโ€™s command reference carefully, since its allowed syntax may differ from a standard PowerShell session.

!cash drawer count: The lab wonโ€™t accept Remove-Item or other commands. It only gives me rmdir, attrib, cd, dir, and mkdir, so Iโ€™m trying to follow those restrictions exactly.

Reply to this answer
!try a softer pencil
The course material may be describing a different command environment or may have a confusing example. Options such as -h and +h can mean different things depending on whether you are using a command prompt utility, PowerShell, or a training simulator. Use the exact syntax documented for the lab rather than assuming the Microsoft PowerShell syntax applies there.

!cash drawer count: That seems to be the issue. The instructions are confusing because some examples use switches differently from the official documentation, and the lab only accepts a limited set of commands.

Reply to this answer
!6 tiles loose
First use dir to inspect the folder and confirm the path is correct. If the files are hidden or read-only, attrib can help identify or clear those attributes. A message saying the path canโ€™t be found usually means the drive letter, spelling, or current lab environment doesnโ€™t match the example path. Make sure D:softwarearch98 actually exists before trying to remove it.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions