How to delete folders or files regularly by using Windows scheduled tasks

user:visitors Date:2022-11-08 22:07:361929

In the server of Windows Server system, to operate the file or folder, you can use the cmd command or batch file in addition to manual operation

Delete the specified file in cmd, mainly including del or erase

We can type del/? In the cmd command prompt panel? Used to view all cmd command details

/F Forcibly delete the specified read-only file

/PA confirmation prompt pops up before deleting each file

/Q No confirmation is required when deleting global wildcards, quiet mode

/S Delete files in all subdirectories

/A Delete files according to attributes a: archive files r: read-only files s: system files h: hidden files l: reparse points -: indicates no i: no content index files

Common commands for deleting files are:

1. Delete the specified file

del C:\zdwj\1.txt

It means to delete the 1.txt file in the zdwj directory of the C drive

2. Delete the specified suffix file

del C:\zdwj2\*. jpg *.png

Where * is a wildcard character that matches all file names with the specified suffix

3. Delete all files in the specified folder

del /f /s /q C:\zdwj3\    

In Win, delete the specified file and use del to name it, and delete the specified directory and use rmdir. We can enter rmdir/? View all the parameters of the rmdir command

/S Delete the specified directory including subdirectories and files in subdirectories

/Q Do not prompt whether to delete the directory when deleting it, silent mode

Common operations to delete a directory include:

1. Delete the specified directory

rmdir C:\zdwj1\1\

When the folder name 1 directory is empty, it means to delete the subdirectory named 1 under the zdwj directory on disk C

2. Non empty directory deletion

rmdir /s C:\zdwj2\1\

3. Delete directory and all subdirectories directly

rmdir /s /q C:\zdwj3\1\

The above commands need to be typed into the cmd panel for execution before they can be deleted. In order to regularly delete the specified directory or file, we also need to change the code that needs to execute the task into a. bat file

It is also very simple to create. Use the simplest notepad, save as, and then select all files as the type. The file name and suffix are changed from XXX.txt to XXX.bat. Right click Edit to copy the task code to be executed

Search the task scheduler in the Start menu, open it, and select the Create button in the right operation panel to create a task

Customize the name of a deletion task in the creation panel. You can write it freely

Then select the sub panel: Trigger, New - New Trigger. Set the number of times to execute the task, the start time, and the interval between repeated tasks in the panel

If it needs to be executed twice a day, select Daily, and then tick Repeat Interval Setting Interval 12 Hours - OK Setting

Continue to switch to the operation panel - New - Operation Select the startup program, browse to the program or script column, and find the deletion command file XXX. bat that we created. Finally, confirm to save, and then you can regularly delete the specified folder or file every day

Popular articles
latest article