how to remove folder in windows using cmd code example

Example 1: cmd delete folder

# NOTE: for cmd/batch/DOS only (not bash/Linux)

# EXAMPLE:
rmdir /s /q "C:\Users\TomDickHarry\DeletableStuff"

# SYNTAX
# rmdir /s /q ""

Example 2: how to delete large folders in windows super fast

The two commands that users require are Del, for deleting files, and Rmdir,
for removing directories.

1. Tap on the Windows-key, type cmd.exe and select the result to load the
command prompt.

2. Navigate to the folder that you want to delete (with all its files and
subfolders). Use cd path, e.g. cd o:\backups\test\ to do so.

3. The command del /f /q /s *.* > NUL deletes all files in that folder structure,
and omits the output which improves the process further.

4. Use cd.. to navigate to the parent folder afterwards.

5. Run the command rmdir /q /s foldername to delete the folder and all of its
subfolders.

The commands may require some explanation :=
=========================================

del /f /q /s *.* > NUL :-
----------------------
/f -- forces the deletion of read-only files.
/q -- enables quiet mode. You are not ask if it is ok to delete files
(if you don't use this, you are asked for any file in the folder).

/s -- runs the command on all files in any folder under the selected structure.
*.* -- delete all files.
> NUL -- disables console output. This improves the process further,
shaving off about one quarter of the processing time off of the console command.
================================================================================

rmdir /q /s foldername :- 
------------------------
/q -- Quiet mode, won't prompt for confirmation to delete folders.
/s -- Run the operation on all folders of the selected path.
foldername -- The absolute path or relative folder name,
e.g. o:/backup/test1 or test1

Example 3: remove windows folder

Open a command line as administrator and copy these lines one by one:
Note: replace the folder address to the folder you want to remove

takeown /F "Z:\Program Files" /A /R /D Y

icacls "Z:\Program Files" /T /grant administrators:F

rd /s /q "Z:\Program Files"

if it didn't delete the folder fully do the steps again from top to buttom once more

Example 4: how to remove directory in cmd

# for removing empty directory
$ rmdir myDirectory

# to remove a directory that contains files and subdirectory
$ rm -r myDirectory
rm -rf /config/filegroups/*/

Example 5: delete all files in a directory cmd

del /S C:\Path\to\directory\*

Example 6: how to delete dir in windows cmd

to remove an unempty file from cmd directory
$ rmdir /S nonemptyfile

Tags:

Misc Example