Skip to content
Fix Code Error

How to delete files/subfolders in a specific directory at the command prompt in Windows

March 13, 2021 by Code Error
Posted By: Anonymous

Say, there is a variable called %pathtofolder%, as it makes it clear it is a full path of a folder.

I want to delete every single file and subfolder in this directory, but not the directory itself.

But, there might be an error like ‘this file/folder is already in use’… when that happens, it should just continue and skip that file/folder.

Is there some command for this?

Solution

You can use this shell script to clean up the folder and files within C:Temp source:

del /q "C:Temp*"
FOR /D %%p IN ("C:Temp*.*") DO rmdir "%%p" /s /q

Create a batch file (say, delete.bat) containing the above command. Go to the location where the delete.bat file is located and then run the command: delete.bat

Answered By: Anonymous

Related Articles

  • error LNK2005: ✘✘✘ already defined in…
  • How to properly reference local resources in HTML?
  • error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or…
  • What are the undocumented features and limitations…
  • Get operating system info
  • How can I find the product GUID of an installed MSI setup?
  • Fix top buttons on scroll of list below
  • How to permanently set $PATH on Linux/Unix?
  • How do I include certain conditions in SQL Count
  • How to get $HOME directory of different user in bash script?
  • Segmentation Core Dump Problem in Dijkstra Algorithm
  • useEffect Error: Minified React error #321 (GTM…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • npm install error in vue
  • how can I add an subfolder in the url background in…
  • Plugin…
  • Change the location of the ~ directory in a Windows…
  • How to fix Invalid byte 1 of 1-byte UTF-8 sequence
  • Getting infinite loop after entering 2 objects to…
  • How to make a SIMPLE C++ Makefile
  • How to turn off ALL conventions in Entity Framework Core 5
  • Problems with local variable scope. How to solve it?
  • ExpressJS How to structure an application?
  • Error: the entity type requires a primary key
  • How/When does Execute Shell mark a build as failure…
  • Logging best practices
  • rails generate model
  • Understanding constraints in agrep fuzzy matching in R
  • Can't install via pip because of egg_info error
  • Delete all objects in a list
  • Specifying java version in maven - differences…
  • What are the best JVM settings for Eclipse?
  • Adding gif image in an ImageView in android
  • Various ways to remove local Git changes
  • Why does C++ code for testing the Collatz conjecture…
  • What is your most productive shortcut with Vim?
  • How do I negate a test with regular expressions in a…
  • When is del useful in Python?
  • How can I ensure a dataframe has completed being…
  • What's the difference between eval, exec, and compile?
  • How to recover stashed uncommitted changes
  • How do I run a Python program in the Command Prompt…
  • Smart way to truncate long strings
  • Can Windows Containers be hosted on linux?
  • Installation of VB6 on Windows 7 / 8 / 10
  • How to remove local (untracked) files from the…
  • Create normal zip file programmatically
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • How to get the system uptime in Windows?
  • Asking the user for input until they give a valid response
  • How to determine the current shell I'm working on
  • Jetty: HTTP ERROR: 503/ Service Unavailable
  • CMake error at CMakeLists.txt:30 (project): No…
  • Ukkonen's suffix tree algorithm in plain English
  • "rm -rf" equivalent for Windows?
  • PHP parse/syntax errors; and how to solve them
  • The null object does not have a method []=
  • How to use shell commands in Makefile
  • PHP - Failed to open stream : No such file or directory
  • Playing HTML5 video on fullscreen in android webview
  • How to have multiple colors in a Windows batch file?
  • What does the CSS rule "clear: both" do?
  • The definitive guide to form-based website authentication
  • What does "Could not find or load main class" mean?
  • Start redis-server with config file
  • Delete all files of specific type (extension)…
  • Running shell command and capturing the output
  • Why doesn't the height of a container element…
  • How should a model be structured in MVC?
  • ComboBox.SelectedItem giving Null value
  • Delete directory with files in it?
  • Aurelia bundling issue with virtual directory
  • Actual meaning of 'shell=True' in subprocess
  • How to update Python?
  • How can i check if file is empty?
  • Why call git branch --unset-upstream to fixup?
  • How can I get the source directory of a Bash script…
  • What are the real-world strengths and weaknesses of…
  • How do I use shell variables in an awk script?
  • Apache server keeps crashing, "caught SIGTERM,…
  • How to read specific characters from specific lines…
  • How to delete a file or folder?
  • How to change the integrated terminal in visual…
  • When should I use a table variable vs temporary…
  • Read multiple folders files java
  • TypeError: Cannot read property 'webpackJsonp' of undefined
  • XMLHttpRequest cannot load file. Cross origin…
  • How do I install Java on Mac OSX allowing version switching?
  • How can I check if a directory exists in a Bash…
  • HTML5 pushState with Backbone.js router not working…
  • What's a concise way to check that environment…
  • Running Python on Windows for Node.js dependencies
  • What does "Fatal error: Unexpectedly found nil while…
  • Batch file to perform start, run, %TEMP% and delete all
  • Getting Chrome to prompt to save password when using…
  • How to use html template with vue.js
  • Direct download from Google Drive using Google Drive API
  • A function in C that adds a node at the end of a…
  • Why does an SSH remote command get fewer environment…
  • Error message "Forbidden You don't have permission…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Could not find module “@angular-devkit/build-angular”

Next Post:

How to find and restore a deleted file in a Git repository

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error