recent
أخبار ساخنة

Remove folders using Batch script



How to delete folder in Batch?

To remove and delete any folder using batch script, you will need the new rd command, which stands for remove directory. So, to remove directory in batch environment, the following instruction may be followed:


1- Open the notepad or any other text editor.

2- Turn the echo command off by typing @echo off

3- Use the command line rd followed by the folder name you want to delete it.

4- Save the command lines as .bat file.

5- Run the batch file.

After running the batch, the folder that you want to delete it, will no longer be exist, and removed directly.
However, if the folder were not empty and include some files inside, then the command prompt will appear “The directory is not empty.”  Followed by the line press any key to continue. Therefore, we must add the suffix /s.

How to remove not empty folder using batch commands?

As mentioned, we may use the command rd followed by the suffix /s followed be the non-empty folder name. So, if we want to delete the non-empty folder name test using the batch script, we do the following
@echo off
rd /s test
Pause
After implementing and executing the batch script code, the following message appear, to confirm the deletion process for the non-empty test folder
Test, Are you sure (Y/N)?
Pressing the y letter will execute the folder removal and all of its content, unless one ore more of its content were used by any software or program.

How to delete non-empty folder without prompt y/n message?

To remove any folder and its content without showing prompt message, we can use another suffix coupled with the previous one which is /q. therefore, if we want to delete the test folder and all its content without any prompt message, we write the following code
@echo off
rd /q /s test
Pause
This will remove the test folder and everything inside it without asking. i.e. deleting in silent mode. Thus, this is how to skip "are you sure Y/N" when deleting files and folders in batch code.


author-img
العلم للجميع

تعليقات

ليست هناك تعليقات
إرسال تعليق
    google-playkhamsatmostaqltradent