Im new to cmd, and I was given a task to delete a directory, without deleting its content, in one line.
How can I do that?
I had already tried rmdir
and del
, but they remove the content of the directory along with it.
I thought about using move
first in order to move the content, but I have no idea as for how to do it along with deleting the folder in one line.
Any help would be much appreciated
Asked
Active
Viewed 194 times
0

Castleking1810
- 77
- 1
- 11
-
Why one line? You can't delete the directory without moving the files and I can't think of a tool that handles it as a single command. – shawnt00 Aug 16 '20 at 14:09
-
that was the task i was given, i don't know why. im just trying to solve it – Castleking1810 Aug 16 '20 at 14:11
1 Answers
0
Like this on all Microsoft OSes since 2000, and still good today:
dir & echo foo
If you want the second command to execute only if the first exited successfully:
dir && echo foo
As answered here.
So you can easily move, then delete the folder all in one line.

Merritt
- 445
- 1
- 6
- 14
-
If this solves your question please mark as solved for future users reference :) – Merritt Aug 16 '20 at 15:23
-
1@Erel, please do not mark this answer as the solution to your question, because it is not. This shows you two methods of combining one or more commands as a single line, it does not move contents or delete/remove objects. It is therefore an incomplete answer, technically it assists you with only a portion of what your question asks. If you only wanted to know how to combine multiple commands onto a single line, then you should upvote the linked answer, and delete your question, or edit your question accordingl, and it will be closed as a duplicate of that linked above. – Compo Aug 16 '20 at 16:00