Deleting files in a folder via cmd. An example of using forfiles is to display all .zip files on disk and write them to a file

Command Line (abbreviated as CMD) – special program, allowing you to perform complex operations in Windows. Ordinary users do not use it, since the need for most functions is realized through the familiar window interface. But when bigger problems arise, command line capabilities can come in handy. This program suitable for forcibly deleting folders, files and working with directories and local drives.

The essence of the work is simple - a command or a series of sequential commands (algorithm) is entered, and Windows executes them. Moreover, many processes go through CMD much faster than in the familiar graphical interface. Deleting a folder or program on the command line generally takes a couple of clicks.

We'll be using CMD a lot in this tutorial, so let's look at launching it first. To open the program, use one of the methods below.

Method 1

In the Start search, type “command prompt” or “cmd” (without quotes). The system will find the utility, all you have to do is open it.

If you want to find out in more detail, and also consider 5 proven methods, you can read an article about this on our portal.

Method 2


Note! CMD can only be launched by the computer administrator. Since the command line is capable of making serious changes to the operation of the system, Windows OS does not trust other users (with the “Guest” and “Regular” rights categories) to run it.

How to delete a folder via command line

Step 1. Launch CMD.

Step 2. To delete, use the command “rmdir” (rd) - delete the file directory Windows systems only possible with her help. So, enter the text “RD /?”. The utility will introduce you to the functions for working with folders.

Step 3. We created a folder with unnecessary files to demonstrate how the utility works. The folder is located on the desktop. When you delete a folder, you must enter the following command: “RD /s”, then put a space and enter the path to the folder itself (its address on the computer).

How to find the folder path

How to find out the path to a folder? Doing this manually takes too long, especially if you want to delete several directories. Let's take a look at our desktop. It is located in the “Users” folder on the drive where you have Windows installed.

  1. In our case, the system is located on the local drive C. We go into it.

  2. Then to the users directory.

  3. And then we select a specific user.

  4. There we see the “Desktop” - open it.

  5. At the end of the path we should come to the folder that needs to be deleted.

  6. Now click on the address bar of the explorer (see screenshot) and copy the address (key combination “Ctrl + C”).

Important! The method is applicable to any option: deleting a folder with or without confirmation - there is no difference.

Step 4. Paste the folder address into CMD. To do this, click right click mouse next to the entered command on "Step 3"(unfortunately, the keyboard shortcut “Ctrl+V” in the command line does not work). Press "Enter".

Step 5. The utility will ask if you really need to delete the directory. If you are sure that yes, press the English key “Y”, and then “Enter”.

Step 6. Ready! The folder has been deleted using the command line. Just in case, let's check that the directory is missing.

Note! The folder is completely deleted from the hard drive, not being placed in the Recycle Bin! Be careful when using this tool - you may inadvertently delete important data from your computer permanently. Only the main user of the computer can delete a folder with administrator rights.

How to delete a file via command line

The principle of uninstalling a file is not much different from deleting a folder. We will also need to find out the file address and write it in CMD. The only difference is the team itself.

Step 1. Open CMD.

Step 2. Enter the following command: “DEL /F /S /Q /A”. Then put a space and insert the path to the file.

How to find out the path to a file?


Step 3. Paste the copied text into CMD (it must be in quotes).

Step 4. Now copy the file name from the field (along with the extension - see screenshot) and paste it into CMD.

Step 5. Close the quotes and press Enter.

Done – the file is deleted forever.

How to remove a program via the command line in Windows 7

It happens that the program is not removed by the standard Windows application(from control panel). To permanently remove software, clearing not only its files, but also data in the registry, the command line is useful.

Step 1. Launch CMD.

Step 2. We drive in “wmic”.

Step 3. Now you need to find out the names of a specific application in Windows so as not to make a mistake and delete useful software. To do this, type in “product get name” (literally, “get the name of the product”).

Step 4. Uninstall the program on the command line. All that remains is to enter the text “product where name=”program name” call uninstall”. The text in quotes is the name of the software of their list provided by the command line.

Step 5. Ready! You can check whether the software has been removed or not by going to the “Uninstall a program” application from the “Control Panel”. If the software is not in the list, it means the operation was completed successfully.

How to change to another drive on the command line

To navigate through directories and local drives, a familiar navigation tool is used - Explorer. However, using CMD you can navigate to directories located on the hard drive.

This instruction answers the question “how to go to another folder on the command line”; there is no fundamental difference between the directory and the local partitions of the hard drive.

Step 1. Launch CMD.

Step 2. Type in the command “cd /d “d:””. In quotes is our address local disk or directories.

In the field, enter the command “cd /d “d:””, in quotes - the address of our local disk or directory, press “Enter”

How to make a bat file

Bat file is an algorithm that can be written by the user in the CMD utility. Regarding our topic, it is possible to delete a folder using the command bat file a, entering the sequence of steps. Instructions for creating a BAT file:

Step 1. Create a simple document in Notepad.

Step 2. You can put a few spaces or some simple text. This is done so that the file is saved by the program (the main thing is that it is not empty). Now this does not play a big role, since we use the Notepad++ utility to create the BAT file.

Step 3. Download Notepad. We install.

Step 4. Let's open our document.

Step 5. In the menu, select “Encodings” -> “Cyrillic” -> “OEM 866”.

Step 6. Go to the “File” tab and select “Save As”. We confirm the action and replace the old file with a new one.

Step 7 Now you can delete the old contents of the file and enter the desired algorithm.

Step 8 Save the document and change the extension from txt to bat.

Video - How to delete a folder using the command line (cmd) in Windows

You can delete a folder by right-clicking on it and selecting delete in the context menu. But sometimes this method does not help and I cannot delete the folder, so I will describe several ways to delete the folder.

Deleting a folder using the command line

To delete Windows folder we do the following. Click “Start” - “All Programs” - “Accessories” - “Command Prompt”. A window will appear in which if you add Help and press “Enter”, a list of commands and a description about each command will appear, the RMDIR command is deleting a folder via command line. To find out how to write the command you need, for example deleting a folder, you need to add Help RMDIR. The system told us how to write a command to delete a folder. RMDIR [drive:]path. I want to delete the remains of the game paradise in the RAI folder and I got this command. RMDIR /S /Q C:\Games\RAI.

Delete a folder via command line

Press “Enter” and the folder will be deleted immediately.

Deleting a folder using the bat file command

So we found out what the command to delete a folder looks like. There are folders that appear again after some time. To remove them, you can create a BAT file on your desktop because this folder, which we do not need, will be deleted when you run the bat file.

How to make a bat file

Right-click on an empty space on the desktop and select “Create” - “Text Document” from the context menu. Let's open this Text Document, which appeared on the desktop. Enter the command RMDIR /S /Q C:\Games\RAI there, where C:\Games\RAI is the path to your folder. The entire path must be in English because the bat file will not run if there are words in Russian in the written bat file. Now click “File” - “Save As”. In the window that appears, in the file name line, write 1.bat and click “Save”.


In 1.bat rename the file

An example bat file will appear on your desktop. Now run 1 bat file and bat delete the folder instantly.

Removing the Windows old folder

Some install the system without formatting the disk and they end up with a folder with system files old windows This folder is usually called Windows old. Many people do not know that the Windows old folder can be deleted. You can delete the old windows folder by using Disk Cleanup in Windows 7. Click “Start” - “All Programs” - “Accessories” - “System Tools” - “Disk Cleanup”. A window will open in which you need to select the drive on which the Windows old folder is located and click “OK”. The disk will be scanned and a window will appear in which we click “Clean up system files.” In this window, put a tick in the “Previous Windows installations" and click "OK". A message will appear saying “Are you sure you want to permanently delete these files?” click “Delete files”.

Removing windows old

System files will be deleted from the Windows old folder and now you can simply delete the Windows old folder.

Delete a folder with administrator rights

Sometimes the folder is not deleted and the message “You need permission to perform this operation” appears and in order for the folder to be deleted you need to allow it in the folder properties full access To do this, we do the following. Right-click on the folder and select “Properties” from the context menu. Go to the “Security” tab and click “Advanced”. In the new window, go to the “Owner” tab and click “Change”.


We will change the owner of the folder

The owner window will open in which you need to select your administrator name (but not administrators), check the box “Replace owner of subcontainers and objects” and click “Apply”.


Changing the owner of a folder

In the message that appears, we confirm and become the owner of this object. From the “Owner” tab, go to the “Permissions” tab and click “Change Permissions”. In the window that opens, select the name of your administrator and click “Change”. A window will open in which we put a tick in the “Full access” item and click “OK” this window will close, and in open window check the boxes:
"Add permissions inherited from parent objects."
“Replace all permissions of the child object with permissions inherited from this object” and click “OK”.


Allow full access to the folder

A message will appear again with which we agree by clicking “OK” and close all windows by clicking “OK”. Now the folder can be deleted.

Deleting a folder in Total Commander

Permanently delete a folder in Total Commander very easy. You need to find the folder you need to delete and click on it with the left mouse button, and then click the delete button at the bottom of Total Commander or press F8 on the keyboard and a message will appear in which we click “Yes” or “Delete”, depending on whether the folder is empty or there is something in it that is.


Finding and deleting empty folders in total commander

The folder will be deleted along with all its contents.

Program to force folder deletion

I like the Unlocker folder deletion program.

Install and the program for deleting non-deletable folders will be in the context menu. Right-click on the folder to be deleted and select Unlocker from the context menu. A window will appear in which set the action to “Delete” and click “Unblock all”. The folder will be deleted.

Many users are faced with a situation where, when starting the computer, a command prompt window appears and disappears indicating the source - C:\Windows\System32\cmd.exe. In especially severe cases, such a window can pop up constantly, which is quite annoying. Most often the window appears in Windows 10, less often in versions 7, 8. In the article we will explain in detail the reasons for this phenomenon and show how to remove this window.

What causes the cmd.exe line to appear?

The specific source of the appearance of the command line “C:\Windows\System32\cmd.exe” is an autorun process, and it can be a system service or third party application, and viral activity. It is necessary to distinguish between two situations in which such a window pops up:

  1. In the moment Windows startup. The desktop loads, and then a line window appears. Most often this is due to some OS service running in the background. The more powerful your hardware, the faster cmd loads and disappears.
  2. The window appears constantly (periodically) during operation. In this case, you need to say that the background process is constantly “freezing”, cannot boot, or is blocked by the system.

I encountered exactly the first situation, my line appears for literally a few seconds and closes. It does not cause any discomfort.

Is this kind of autorun dangerous?

In most cases, the source is a system process and is absolutely harmless. The operating system, during the loading and operation process, constantly activates thousands background processes and hundreds of services. Imagine that the execution of one “heavy” service slows down, and if your CPU is weak, then the freezing time only increases. This is especially often observed on dozens, which are more demanding on hardware.

It's another matter when third-party software tries to execute its commands. And it’s even worse when virus activity in the background loads the computer.

How to remove the cmd.exe command line that opens?

In any case, to identify the source of the pop-up line, it is necessary to carry out a comprehensive cleaning and check Windows settings 7/8/10. Here's what to do first:


These are all general tips - half measures, so to speak, that will help with minor failures and broken parameters. Otherwise, you will have to manually check everything.

Removing pop-up cmd.exe using Scheduler

To start, type “Task Scheduler” into the search menu or write in Perform operation – taskschd.msc. Afterwards the PZ menu will open, and we do the following:


After you remove/disable everything unnecessary, the command line should disappear. A similar procedure can be carried out by erasing run files in the registry - here is a visual video.

Recommendations will help you completely delete a folder via command line. In the article about, the DEL command was used, which is intended specifically for files. In the case of folders, the RD or RMDIR commands are applicable.

To achieve the goal, . Enter RD /? and quickly familiarize yourself with the features and parameters of the command. Here you will see only 2 parameters:

  1. /s - when using this prefix, the folder will be deleted, as well as all its nested elements. If your directory is not empty, and you have not specified this parameter, then nothing will work for you.
  2. /Q - used when deleting without confirmation.

IN general view the design looks like this:

RD or RMDIR /s/q “ full path folders"

Note: when applying the design, the directory and its contents will be completely deleted from the computer and you will not find it in the trash. For safety, do backup copy folders.

Deleting a folder with or without confirmation

I created a directory on my computer called “cmd” and copied several objects into it. Then I entered the following command into the command line:

RD /s “c:\cmd”

Then I pressed Enter and the Y key because cmd prompted me to confirm the deletion.

I checked the C drive and found no directory. Next, I created a folder named “delete” and also copied 5 files, but when entering the command, I removed the /s prefix. It turned out like this:

RMDIR “c:\delete”

After pressing Enter, the deletion did not occur, and a message was displayed on the command line that the folder was not empty. Conclusion, without the /s parameter, you can only delete an empty folder, therefore, using it without this prefix is ​​practically useless.

If you are too lazy to enter the confirmation letter (Y or N), then the following construction is for you. The /q prefix was mentioned above; it is what removes the annoying typing of letters (see the screenshot for proof).

As Zhora Kornev from Terminator Three said, “Hacker Magazine is a must-read,” and it’s true that it’s probably difficult to find a young user these days who lives on the Internet and has never wondered about hacking something, or at worst, deleting it system file in the command line of your neighbor. Perhaps the most desirable prey for the RuNet is social network In contact with.

Yandex alone contains 61 thousand sites with a pure entry “how to hack VKontakte”! Well, it's just hack territory! But... there are few skilled people to create high-quality websites, and even fewer skilled people to provide worthwhile information, not to mention the fact that most hack manuals are banal copy-paste or rewriting. Causing harm to someone else's system is not so easy, but ruining your own hardware is a trifle. And so, let’s get started, since time is running out for me (special forces in helmets are grazing under the doors), and the user should not be taken by Murziki, I decided to continue writing posts in the “Working with the command line” section, and in this I will do short review del command line utility, which allows you to delete one or a group of files and even programs. I advise you to read an article about the topic.

The first thought that comes to any dirty trickster’s mind is to fucking delete everything. At one time, while sitting in a local area during an informatics lesson, I hacked my neighbor’s entire Windows, he was so upset, he thought he had opened the notepad incorrectly. Watching Hollywood films about evil hackers, you can usually see how a certain Hrundel sticks into a black screen and enters incomprehensible words from the keyboard, and he has full access to the FBI database. Well, as they say, we are worse. And so, we create a smart look, tell our friends to close the curtains, and launch... the CMD command line (Black screen, no matter how). Perhaps it is nostalgia and Western films that give the illusion that you can kill an enemy computer using the command shell. But...this is just the tip of the iceberg.

And so, let’s say we, having read secret waste paper, decided to create a virus, but not wanting to study assembly programming at school leaves only one choice - creating a bat virus. The essence of the virus will be simple and banal - delete the Windows folder and all its files using the command line. Well, let's try...

DEL command line utility

This command contains the following set of parameters:

DEL [drive:] [path]filename]

[drive:] [path]filename - everything is clear here, enters the path to the object that we want to delete, for example a record

Del D:\data.txt- will delete the text file D:data.txt

Team del d:\temp is designed to delete all data stored in the temp directory, but if it contains a subfolder with files, they will not be touched. Additional attributes allow you to control the deletion process:

/P– this attribute will ask for consent to destroy each object stored in the directory

/F– deletes an object, even with the Read-Only attribute

/S– this option will allow you to delete all files via the command line, including data in subdirectories

/Q– disable the display of a request to confirm destruction.

/A[: attributes] – this attribute is good because it allows you to kill only certain objects, for example, those with the following attributes:

R- "Only for reading",

N- "Hidden"

S- "System"

A- "Archival".

Second additional opportunity is – specifying a mask of objects to be killed using wildcards: ? (any one character) and * (any number of characters). That is, the entry:

DEL D:\Temp\data*.txt /s/f– will delete everything via the command line text files, starting with data.

Well, this seems clear, but how to use such meager knowledge for the benefit of the fatherland, so to speak? On one site I came across a rather heated discussion about the creation of batch files; young people vigorously gave examples of their “mega” viruses. And so, using the above command, let's try to write a virus that will supposedly delete the system folder, change the volume label, mock extensions and reboot the computer:

@echo off
label LAMER
assoc.exe=.gif
del %windir%*.* /q/f /s
shutdown -r –f

The first line disables the output of text and commands, the second changes the disk label to Lamer. Team assoc.exe=.gif causes the system to consider all executable files to be images. Next comes deleting files in system folder via the command line. Well, and finally - forced reboot without confirmation. There are thousands of such examples, and this one is the most lame, and for them to work, you need to take into account a lot of nuances:

  • Common dirty tricks (such as turning off the mouse or keyboard) are immediately stopped by the antivirus program.
  • Register the path to batch file in startup (as a rule, the registry is suitable for these purposes) will not work if the user’s rights are limited.
  • Type account And operating system. You can go into more detail here. Seven initially will not allow the execution of a number of command line utilities - only on condition that the launch is made on behalf of the BUILT-IN ADMINISTRATOR ACCOUNT. If you are the proud owner of “simple” XP, then creating a limited account and then setting up access rights to certain resources will allow you to avoid a number of unpleasant situations: money was stolen from webMoney, a virus is always crawling onto a flash drive, someone deleted a file via the command line passwords and much more.

Actually, this is one of the factors in using a script server to solve administrative and other tasks.

What made me laugh the most was when one of the “gifted” creators of the bat virus complained that his creation did not work in Vista and loudly declared that it was screwed.



Loading...
Top