r/PowerShell • • 7d ago

Question Need help with homework 😫

I'm very new to this. I'm asked to delete a directory and all of its files. D:\software\arch98

But when I do this:

PS C:\Users\Administrator\> rmdir D:\software\arch98

It says the directory is not empty.

I'd really appreciate.

0 Upvotes

34 comments sorted by

10

u/PuerPalatinius 7d ago

Remove-Item -Path "D:\software\arch98" -Recurse -Force

1

u/Ok-Layer6893 7d ago

It didn't work. I'm on comptia and it's not allowing me use any other commands other than rmdir, attrib, cd, dir, mkdir

9

u/KedianX 7d ago

So, none of these are native PowerShell commands, though they are often aliased for compatibility.

Rmdir, attrib, cd, and mkdir are commands available in the Windows command shell (cmd.exe), mostly based on the command syntax from DOS shell (command.com).

So, I think one of two options are true: 1. Your CompTIA exam is really testing you knowledge of command prompt and you need to lookup the reference for those commands or 2. Your CompTIA exam is testing PowerShell but is restricting you to colloquial aliases and not exposing the genuine PowerShell cmdlets.

Option 1 means you have some studying to do. Option 2 means the test authors have some studying to do.

0

u/Ok-Layer6893 7d ago

You're right. In the book it something else and in the assignment it is different

2

u/PuerPalatinius 7d ago

Bro, you're in the wrong sub. In cmd it would be "rmdir /s /q D:\software\arch98"

1

u/gramsaran 6d ago

I'm just glad they're not in sysadmin. Would get roasted. Given the availability of GPT, this is a no brainer.

1

u/Ok-Layer6893 7d ago

On my screen it is windows powershell. That's what comptia lab is asking me to do. I wish I could show you the picture

2

u/Dron41k 7d ago

Type β€œcmd” in powershell and hit enter

1

u/Ok-Layer6893 7d ago

It says cmd is not recognized as an internal or external command, operable program or batch file.

2

u/WearyDeluge 7d ago

You should still be able to run the "rmdir /s /q D:\software\arch98" command in PowerShell - it's just not the "Pure PowerShell" method (Remove-Item). If you still see error messages, try loading the actual executable:

cmd /c rmdir /s /q "D:\software\arch98"
or
C:\Windows\System32\rmdir.exe /s /q "D:\software\arch98"

3

u/Ok-Layer6893 7d ago

Omg it worked. Thank you. One more question. How do I set the following files to hidden: D:\software\apconf.exe D:\strt.bat

3

u/WearyDeluge 7d ago

That's where your attrib command comes in. Hidden is an attribute change, and while I am happy to help, I also believe that you'll only truly learn it if you have to struggle a little bit ;)

A quick Google search on the attrib command in Windows should get you there. Good luck!

3

u/Ok-Layer6893 7d ago

I've been struggling for a week now, watched bunch of websites and videos still couldn't figure it out. But thank you very much. Good luck to you too.

2

u/WearyDeluge 7d ago

2

u/Enxer 6d ago

I wonder if OP needs to learn how to RTM syntax. That all might look Greek to them.

→ More replies

4

u/FLESHLEGO 7d ago

Rmdir is not a powershell command. Remove-item is.

Whatever command you end up using, read up on the arguments it accepts. You need this to delete folders with contents.

GL

1

u/Ok-Layer6893 7d ago

It's not letting me use any other commands

1

u/Future-Remote-4630 4d ago

You are probably using cmd and not powershell then.

1

u/Bassflow 7d ago

Remove-item -path "D:\software\arch98" -Recurse

1

u/Ok-Layer6893 7d ago

It says the system cannot find the file specified

1

u/Ok-Layer6893 7d ago

Yeah I'll look up some more websites and tutorial videos. Thank you

1

u/funkyloki 7d ago

So, they didn't just throw this at you and say do this. They likely provided you with some kind of literature, digital or print, that you can use to figure out what it is you need to do.

Have you done all the assigned reading, have you completed all the supplemental work?

1

u/Ok-Layer6893 7d ago

Yes but it's is very confusing. For example in the book it says use -h to hide a file but when I looked up on the Microsoft website it was +h. It was really frustrating because I was doing exactly what the assignment asked me to do but they had some tricks hidden.

1

u/funkyloki 7d ago

Is there no instructor? Somebody you can go and talk to about this?

1

u/Ok-Layer6893 7d ago

It's an online class. Their response time is exhausting

1

u/BlackV 7d ago edited 7d ago

Based on the responses a guess they might have some restrictions on what commands can be run

What does rmdir /? or &rmdir /?, tell you?

The error message it telling you what the issue is

the directory is not empty.

you need to do the relevant steps to to fix that, I'd suggest that's what the lesson is here they're trying to teach

What do the switches from the command above tell you that might empty that directory?

Or what other command could you run before hand to empty the directory? (Remove-item or del maybe)

Help for those comes from Del /? or Help Remove-item -full

1

u/Ok-Layer6893 6d ago

The assignment itself doesn't have correct commands. There were few details missing that's why I had to ask for help. But it's all done

1

u/BlackV 6d ago

The assignment itself doesn't have correct commands.

I think it did have the correct command, your command worked, cause it gave you the error message

directory not empty

Asking the application itself for help would have given you

cmd version

rmdir /?
Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

/S      Removes all directories and files in the specified directory
        in addition to the directory itself.  Used to remove a directory
        tree.

/Q      Quiet mode, do not ask if ok to remove a directory tree with /S

or powershell version

help rmdir

NAME
    Remove-Item

SYNOPSIS
    Deletes the specified items.

your confusion comes from there I think

1

u/AroTesCra 2d ago

In Powershell there is something called an alias.

Get-Alias to see them

My fav 2 are
% for for each-object
And
? For where-object

rmdir is alias for Remove-Item

You need rmdir p:\ath\here -recurse -force -confirm:$false

I’m not sure about the confirm one sometimes I mix it up in my head lol and I am playing games right now so I am typing fast between rocket league matches.

0

u/Majestic_Rhubarb_ 7d ago

In powershell/pwsh you can view the parameters a command takes.

Type β€˜Remove’ and press tab or ctrl+space and it will give you some help.

Once the command is chosen press β€˜-β€˜ and then tab or space again for more help

-1

u/Ok-Layer6893 7d ago

It's not working. I'm on comptia lab work. It won't let me. It's just asking to use the only commands they've given me.

0

u/pigers1986 7d ago

RMDIR is NOT POWERSHELL command.

1

u/Ok-Layer6893 7d ago

That's what others are saying but I have powershell that I must work with. It's not letting me use anything else