[Win8.x] Deleting the files and directories of an directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

[Win8.x] Deleting the files and directories of an directory

#1 Post by balubeto » 17 Apr 2015 04:51

Hi

With the Command Prompt in Windows 8.x, which command should I use to delete all files and all subdirectories of a directory without deleting this root directory?

Thanks

Bye

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [Win8.x] Deleting the files and directories of an direct

#2 Post by foxidrive » 17 Apr 2015 10:03

Code: Select all

pushd "d:\files" && ( rmdir /s/q "d:\files" 2>nul & popd )

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: [Win8.x] Deleting the files and directories of an direct

#3 Post by balubeto » 17 Apr 2015 11:54

foxidrive wrote:

Code: Select all

pushd "d:\files" && ( rmdir /s/q "d:\files" 2>nul & popd )


It works well but I have a problem:

This command must be run from another directory and, at the end of its execution, should I find myself in the same starting directory.

So, how do I reach my goal?

Thanks

Bye

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: [Win8.x] Deleting the files and directories of an direct

#4 Post by Squashman » 17 Apr 2015 11:56

The PUSHD changes to the directory you need to process. The POPD returns you to the original directory. Are you saying that is not what is happening?

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: [Win8.x] Deleting the files and directories of an direct

#5 Post by balubeto » 18 Apr 2015 00:51

Squashman wrote:The PUSHD changes to the directory you need to process. The POPD returns you to the original directory. Are you saying that is not what is happening?


Strange. When I run this command on Windows 8.x, I find myself in the directory indicated by the pushd command and not in the starting directory. Why?

Thanks

Bye

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [Win8.x] Deleting the files and directories of an direct

#6 Post by foxidrive » 18 Apr 2015 02:12

balubeto wrote:Strange. When I run this command on Windows 8.x, I find myself in the directory indicated by the pushd command and not in the starting directory. Why?


Give us a clue how you launched the batch file.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: [Win8.x] Deleting the files and directories of an direct

#7 Post by Squashman » 23 Apr 2015 07:49

My Goodness. You asked this same question almost three years ago and we answered it basically the same way.
viewtopic.php?f=3&t=3301

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [Win8.x] Deleting the files and directories of an direct

#8 Post by foxidrive » 23 Apr 2015 08:19

Squashman wrote:My Goodness.


Your google fu is strong. :D

Post Reply