大网数据广告活动
Windows排障命令

erase

· 52CE 我爱测

Reference article for the erase command, which deletes one or more files.

Deletes one or more files. If you use erase to delete a file from your disk, you can't retrieve it.

Note: This command is the same as the del command.

Syntax

erase [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>
del [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>

Parameters

Parameter Description
<names> Specifies a list of one or more files or directories. Wildcards may be used to delete multiple files. If a directory is specified, all files within the directory will be deleted.
/p Prompts for confirmation before deleting the specified file.
/f Forces deletion of read-only files.
/s Deletes specified files from the current directory and all subdirectories. Displays the names of the files as they are being deleted.
/q Specifies quiet mode. You are not prompted for delete confirmation.
/a[:]<attributes> Deletes files based on the following file attributes:<ul><li>r Read-only files</li><li>h Hidden files</li><li>i Not content indexed files</li><li>s System files</li><li>a Files ready for archiving</li><li>l Reparse points</li><li>- Used as a prefix meaning 'not'</li></ul>
/? Displays help at the command prompt.
Remarks
  • If you use the erase /p command, you'll see the following message:

    FileName, Delete (Y/N)?

    To confirm the deletion, press Y. To cancel the deletion and to display the next file name (if you specified a group of files), press N. To stop the erase command, press CTRL+C.

  • If you disable command extension, the /s parameter will display the names of any files that weren't found ,instead of displaying the names of files that are being deleted.

  • If you specify specific folders in the <names> parameter, all of the included files will also be deleted. For example, if you want to delete all of the files in the \work folder, type:

    erase \work
    
  • You can use wildcards (* and ?) to delete more than one file at a time. However, to avoid deleting files unintentionally, you should use wildcards cautiously. For example, if you type the following command:

    erase *.*
    

    The erase command displays the following prompt:

    Are you sure (Y/N)?

    To delete all of the files in the current directory, press Y and then press ENTER. To cancel the deletion, press N and then press ENTER.

    [!NOTE] Before you use wildcard characters with the erase command, use the same wildcard characters with the dir command to list all the files that will be deleted.

Examples

To delete all the files in a folder named Test on drive C, type either of the following:

erase c:\test
erase c:\test\*.*

To delete all files with the .bat file name extension from the current directory, type:

erase *.bat

To delete all read-only files in the current directory, type:

erase /a:r *.*

Related links

Source: Microsoft Learn / Windows Server documentation by Microsoft and contributors (upstream author metadata: robinharwood). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Server documentation
适用范围
Windows Server · Source date 10/16/2017
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。