CINXE.COM

Del - Delete Files - Windows CMD - SS64.com

<!doctype html><html lang="en"> <head><meta charset="UTF-8"> <meta name="viewport" content="width=768, initial-scale=1"> <link rel="stylesheet" href="../main.css" type="text/css"> <link rel="icon" href="/favicon.ico" sizes="48x48"> <link rel="icon" href="/favicon.svg" sizes="any" type="image/svg+xml"> <title>Del - Delete Files - Windows CMD - SS64.com</title> <link rel="canonical" href="https://ss64.com/nt/del.html"> <script async src="/js/q.js"></script> <script async src="/js/content.js"></script> </head><body><!-- #BeginLibraryItem "/Library/head_nt.lbi" --><div id="tnav"><ul> <li class="tbtn"><a href="../">SS64</a></li> <li class="tbtn"><a href="../nt">CMD <svg viewBox="0 0 13 20.1" width="13" height="13" style="transform: rotate(0deg);"><path d="M0 2.9l7.2 7.2-7.1 7.1L3 20.1l7.1-7.1 2.9-2.9L2.9 0 0 2.9"></path></svg></a></li> <li class="tbtn"><a href="syntax.html">How-to <svg viewBox="0 0 13 20.1" width="13" height="13" style="transform: rotate(0deg);"><path d="M0 2.9l7.2 7.2-7.1 7.1L3 20.1l7.1-7.1 2.9-2.9L2.9 0 0 2.9"></path></svg></a></li> <li><div id="search"><form action="https://www.google.com/search" method="get"> <input type="text" name="q" id="qu" size="27" maxlength="255" aria-label="Search text"> <input class="submit mousetrap" value="Search" id="btn" type="submit"> <input type="hidden" name="sitesearch" value="ss64.com/nt/"><input type="hidden" name="udm" value="14"></form></div></li> </ul></div><!-- #EndLibraryItem --><h1>DEL</h1> <p>Delete one or more files.</p> <pre>Syntax DEL [<i>options</i>] [/A:<i>file_attributes</i>] <i>files_to_delete</i> Key <i>files_to_delete</i> : A filename or a list of files, may include wildcards. options: /P Give a Yes/No Prompt before deleting. /F Ignore read-only setting and delete anyway (FORCE). /S Delete from all Subfolders (DELTREE). /Q Quiet mode, do not give a Yes/No Prompt before deleting. /A Select files to delete based on <i>file_attributes</i> file_attributes: R Read-only -R NOT Read-only A Archive -A NOT Archive S System -S NOT System H Hidden -H NOT Hidden I Not content indexed. -I Content indexed files. L Reparse points. -L NOT Reparse points. X No scrub file attribute. -X Scrub file attribute. V Integrity attribute. -V NO Integrity attribute. <a href="syntax-wildcards.html">Wildcards</a>: These can be combined with part of a filename * Match any characters ? Match any ONE character</pre> <p>If a folder name is given instead of a file, all files in the folder will be deleted, but the folder itself will not be removed.</p> <p>Errorlevels: DEL will return an <a href="errorlevel.html">Errorlevel</a> of 0, irrespective if the delete succeeds or fails for any reason.<br> Also a deletion failure will not fire for<a href="syntax-redirection.html" class="code"> || </a>unless the DEL arguments are invalid.<br> If you delete files using PowerShell then a True/False return code (<span class="code">$?</span>) will be set correctly.</p> <h2>Errorlevels</h2> <blockquote> <p>If the files were successfully deleted <span class="code"><a href="errorlevel.html">%ERRORLEVEL%</a> = 0</span><br> If the files failed to delete, or don’t exist to be deleted <span class="code"><a href="errorlevel.html">%ERRORLEVEL%</a> = 0</span><br> Bad or no parameters given <span class="code"><a href="errorlevel.html">%ERRORLEVEL%</a> = 1</span></p> </blockquote> <h2>Undeletable Files</h2> <blockquote> <p>Files are sometimes created with a very long filename or a trailing period or with reserved names (CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, NUL) and as a result they become impossible to delete with Windows Explorer.</p> <p>To delete such files use the <a href="syntax-filenames.html">Device Path</a>: <span class="code">DEL &quot;\\?\path to file&quot;</span></p> <p>e,g,<span class="code"><br> DEL &quot;\\?\C:\some folder\AZH64GT.&quot;<br> </span></p> <p>Alternatively for long filenames, you can reduce the total path length by using <a href="subst.html">SUBST</a> to map a drive letter to the folder containing the file.</p> <p>It is also possible to delete long paths using <a href="robocopy.html">RoboCopy</a> - Copy/Move the required files to a temporary folder and then delete the folder, one gotcha with that technique is RoboCopy’s tendency to follow symbolic links which can cause files outside the source folder to be moved/ deleted.</p> <p>If a file is still 'undeletable' this may be caused by the indexing <a href="syntax-services.html">service</a>, temporarily stop the service and then delete the file.</p> <p><b>Thumbs.db</b></p> <p>If you are unable to delete thumbs.db using Windows Explorer or while Explorer is open, this is a bug in the thumbnail view for images. This issue can occur for folders which don’t even contain any images.<br> To resolve, open Explorer, select View ➞ Options, open the &quot;View&quot; tab and uncheck &quot;Display file icon on thumbnails&quot;.<br> For a more permanent <a href="thumbsdb.txt">registry fix</a>, you can disable thumbnail caching completely.</p> </blockquote> <h2>Permanent deletion</h2> <blockquote> <p>Deleting a file will not prevent third party utilities from un-deleting it again. Secure file deletion utilities are available, however for casual use, you can turn any file into a zero-byte file to destroy the file allocation chain like this:<br> <span class="code"><br> TYPE nul &gt; C:\examples\MyFile.txt<br> DEL C:\examples\MyFile.txt</span></p> </blockquote> <h2>Delete Locked files</h2> <blockquote> <p>Typically this is caused by the Offline Cache or Internet Explorer temp files.</p> <p>Close all applications<br> Open a command prompt<br> Click Start, and then Shut Down<br> Simultaneously press CTRL+SHIFT+ALT.<br> While you keep these keys pressed, click Cancel in the Shut Down Windows dialog box.<br> In the command prompt window, navigate to the cache location, and delete all files from the folder (DEL /s)<br> At the command prompt, type explorer, and then press ENTER.</p> </blockquote> <p><b>DELTREE<a id="deltree"></a></b> - Older versions of Windows had the DELTREE command to delete all files and sub folders. This can be replicated with a script as shown on the <a href="deltree.html">DELTREE</a> page.</p> <p>Normally DEL will display a list of the files deleted, if <a href="cmd.html">Command Extensions</a> are disabled; it will instead display a list of any files it cannot find.</p> <p>DEL is an <a href="syntax-internal.html">internal</a> command. ERASE is a synonym for DEL</p> <h3><a id="e" tabindex="-1"></a>Examples</h3> <p>Delete the &quot;Hello World.txt&quot; file in the <a href="cd.html">current</a> directory:</p> <blockquote> <p class="code">DEL &quot;Hello World.txt&quot;</p> </blockquote> <p>Delete 3 named files:</p> <blockquote> <p class="code">DEL file1.txt file2.txt &quot;C:\demo\file3.txt&quot;</p> </blockquote> <p>Delete problematic CrowdStrike files using a wildcard:</p> <blockquote> <p class="code">DEL &quot;C:\Windows\System32\drivers\CrowdStrike\C-00000291*.sys&quot; </p> </blockquote> <p>Delete all files that start with the letter A</p> <blockquote> <p class="code">DEL A*</p> </blockquote> <p>Delete all files that end with the letter A</p> <blockquote> <p class="code">DEL *A.*</p> </blockquote> <p><span class="code"> </span>Delete all files with a .docx extension:</p> <blockquote> <p class="code">DEL *.docx</p> </blockquote> <p>Delete all read only files:</p> <blockquote> <p class="code">DEL /a:R *</p> </blockquote> <p>Delete all files including any that are read only:</p> <blockquote> <p class="code">DEL /F *</p> </blockquote> <p class="quote">“But over all things brooding slept, The quiet sense of something lost” ~ Alfred Tennyson</p> <h3>Related commands</h3> <p class="space"><a href="cipher.html">CIPHER /w</a> - Overwrite data in a directory (secure delete).<br> <a href="delprof.html">DELPROF</a> - Delete user profiles.<br> <a href="deltree.html">DELTREE</a> - Script to Delete a folder and all subfolders/files.<br> <a href="rd.html">RD</a> - Delete folders or entire folder trees.<br> <a href="cleanmgr.html">CleanMgr</a> - Automated cleanup of Temp files, Internet files, downloaded files, recycle bin.<br> <a href="forfiles.html">FORFILES</a> - Delete files older than X days.<br> <a href="https://web.archive.org/web/20050921194716/https://support.microsoft.com/?id=228930">INUSE</a> - updated file replacement utility (may not preserve file permissions).<br> <a href="https://web.archive.org/web/20120215131526/http://support.microsoft.com:80/kb/120716/EN-US">Q120716</a> - Remove Files with Reserved Names.<br> <a href="https://support.microsoft.com/help/320081/">Q320081</a> - You cannot delete a file or folder.<br> <a href="https://web.archive.org/web/20050213173509/https://support.microsoft.com/?id=159199">Q159199</a> - A file cannot be deleted (NTFS).<br> PowerShell: <a href="../ps/remove-item.html">Remove-Item</a> - Delete the specified items.<br> Equivalent bash command (Linux): <a href="../bash/rmdir.html">rmdir</a> / <a href="../bash/rm.html">rm</a> - Remove folders/ files.</p><!-- #BeginLibraryItem "/Library/foot_nt.lbi" --><!-- AuctionX Display platform tag START --> <div id="27677x300x250x4627x_ADSLOT1" clickTrack="%%CLICK_URL_ESC%%"></div> <script async src="https://served-by.pixfuture.com/www/delivery/headerbid.js" slotId="27677x300x250x4627x_ADSLOT1" refreshTime="5" refreshInterval="120"></script><!-- AuctionX Display platform tag END --> <hr> <div id=bl>&nbsp;</div> <div id=br>Copyright &copy; 1999-2025 <a href="https://ss64.com/">SS64.com</a><br> Some rights reserved</div><!-- #EndLibraryItem --></body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10