In Windows, files/folders have a special attribute called hidden attribute. By setting this attribute, we can hide files from being displayed in explorer or command prompt. This article explains how to list this hidden files in windows command line and it also discusses how to delete the hidden files.

To get the list of hidden files from a directory you can run the below command.

dir directory_path /A:H /B

Example:

Get the list of hidden files from C:\Windows\system32 folder.

To get the list of hidden files from all sub directories we need to add /S switch to the command.

dir directory_path /A:H /S /B

Example:
To get the list of hidden files from the folder c:\windows\system32 and from all its subfolders we need to run the below command.

dir c:\WINDOWS\system32 /A:H /B /S

List all hidden folders:

If you want to get the list of all hidden subfolders in a folder, you can run the below command.

dir /s /b /A:DH

Hidden files deletion

To delete hidden files from command prompt we can use Del command. For example to delete a hidden file named example.doc we need to run the below command.

del /A:H example.doc

Note that /A:H is necessary otherwise you will get ‘file not found’ error like below.

C:\>del example.doc
Could Not Find C:\example.doc

To delete all hidden files from a given directory we can run the below command.

del directory_path /A:H

Alternatively you can cd to that directory and then run the below command.

del * /A:H

To delete hidden files from subfolders also you can do that by adding /S switch

del * /A:H /S

If you have the list of hidden folders, then you can delete them all by the following command.
rmdir /s /q hiddenfolder1 hiddenfolder2 hiddenfolder3 .....

If you want to delete all hidden subfolders from a drive/folder then you first need to generate the list of folders and then delete them. This can be done with the below command.
for /F %i in ('dir /s /b /A:DH') do rmdir /s /q %i

Run the above command from the drive or top folder.
Disclaimer: Be cautious while using these commands, as any mistake would lead to data loss. Test and use them at your own risk.

How to delete a single file

Open the command prompt by typing “CMD” in the search field in the taskbar and clicking on “Command Prompt”. Navigate to the folder containing the file to be deleted by using the ‘cd’ command. Type the following command in the command prompt:

DEL /F /Q /A name_of_the_file

/F stands for force delete
/Q will not show Y/N confirmation and will delete the files silently
/A selects only the files with ready for archiving attribute

Alternatively, you can also use the file path directly. For example you can type:

DEL /F /Q /A C:\Users\HP1\Documents\file.txt

If the file is deleted, you will not see any error message.

How to delete a folder

Open the command prompt by typing “CMD” in the search field in the taskbar and clicking on “Command Prompt”. Navigate to the folder containing the folder to be deleted by using the ‘cd’ command. Type the following command in the command prompt:

RD /S /Q name_of_the_folder

RD stands for remove directory.

/S causes the deletion of all subfolders and files

/Q will not show Y/N confirmation and will delete the files silently

Alternatively, you can also use the folder path directly. For example you can type:

RD /S /Q C:\Users\HP1\Documents\folder1

===============

DEL

Delete one or more files.

Syntax
DEL [options] [/A:file_attributes] files_to_delete Key
files_to_delete : 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 file_attributes
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 (Windows 8+)
V Integrity attribute -V NO Integrity attribute (Windows 8+) Wildcards: These can be combined with part of a filename * Match any characters
? Match any ONE character

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.

Errorlevels: DEL will return an Errorlevel of 0, irrespective if the delete succeeds or fails for any reason.
(If you delete files using PowerShell then a True/False return code ($?) will be set correctly.)

Errorlevels

If the files were successfully deleted %ERRORLEVEL% = 0
Bad or no parameters given = 1

Undeletable Files

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.

To delete such files use the syntax: DEL "\\?\path to file"
You can also use
"\\.\path to device"

e,g,
DEL "\\?\C:\some folder\AZH64GT."
DEL "\\.\C:\Work\LPT1"

Alternatively for long filenames, you can reduce the total path length by using SUBST to map a drive letter to the folder containing the file.

It is also possible to delete long paths using RoboCopy - 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.

If a file is still 'undeletable' this may be
caused by the indexing service, temporarily stop the service and then delete the file.

Permanent deletion

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:

TYPE nul > C:\examples\MyFile.txt
DEL C:\examples\MyFile.txt

Delete Locked files

Typically this is caused by the Offline Cache or Internet Explorer temp files.

Close all applications
Open a command prompt
Click Start, and then Shut Down
Simultaneously press CTRL+SHIFT+ALT.
While you keep these keys pressed, click Cancel in the Shut Down Windows dialog
box.
In the command prompt window, navigate to the cache location, and delete all
files from the folder (DEL /s)
At the command prompt, type explorer, and then press ENTER.

DELTREE -
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 DELTREE page.

Examples:

Delete "Hello World.txt"

DEL "Hello World.txt"

Delete 3 named files:

DEL file1.txt file2.txt "C:\demo\file3.txt"

Delete all files that start with the letter A

DEL A*

Delete all files that end with the letter A

DEL *A.*

Delete all files with a .doc extension:

DEL *.doc

Delete all read only files:

DEL /a:R *

Delete all files including any that are read only:

DEL /F *

Normally DEL will display a list of the files deleted, if Command Extensions are disabled; it will instead display a list of any files it cannot find.

DEL is an internal command. ERASE is a synonym for DEL

=============

DEL "C:\Program Files\IBM\ISAM ESSO\AA\Cryptoboxes\Wallets" /A:H  /F /Q 强制静默删除Wallets目录下的所有文件,包括隐藏文件。不包含子目录

												

List or delete hidden files from command prompt(CMD)的更多相关文章

  1. Why the Anaconda command prompt is the first choice in windows?

    为什么在windows里,首选的conda命令行工具是Anaconda command prompt? In windows, what's the difference between comman ...

  2. Qt_Window@Qt Command Prompt从命令行创建工程

    #include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplicatio ...

  3. Visual Studio自带的的Developer Command Prompt对话框

    简单了解Visual Studio的Developer Command Prompt VS2008的命令为:Visual Studio 2008 Command Prompt 目录是: 其详细信息如下 ...

  4. 改变Prompt默认路径,Change Default Visual Studio Command Prompt Location

    在项目中经常需要使用 Visual Studio Command Prompt编译项目,每次启动时都是默认进入 C:\windows\system32> 目录, 需要cd切换路径,如果把Visu ...

  5. Visual Studio Command Prompt 工具配置方法

    有时候,我们无法找到Visual Studio Command Prompt,需要手动配置 打开 Visual studio2015,选择  "工具"—>"外部工具 ...

  6. macOS finder show hidden files

    macOS finder show hidden files 显示 MacOS 上的隐藏文件和文件夹 https://zh.wikihow.com/显示Mac-OS-X上的隐藏文件和文件夹 $ def ...

  7. Find and delete duplicate files

    作用:查找指定目录(一个或多个)及子目录下的所有重复文件,分组列出,并可手动选择或自动随机删除多余重复文件,每组重复文件仅保留一份.(支持文件名有空格,例如:"file  name" ...

  8. VS2010 Command Prompt Error:Cannot determine the location of the VS Common Tools folder

    就在VS2010 Command Prompt 用vcvarsall.bat x64重新设置环境变量的时候,出现了标题中的错误.原因就在参考链接中 References: http://stackov ...

  9. List environment variables from Command Prompt

    Request: List the environment variables from Command Promt To list one varibales , the syntax is lik ...

随机推荐

  1. poj 2752 求一个字符串所有的相同前后缀

    求一个字符串所有的相同前后缀Sample Input ababcababababcababaaaaaSample Output 2 4 9 181 2 3 4 5 #include <iostr ...

  2. 9.Django组件-cookie和session

    HTTP协议的无保存状态,对两次请求没有任何关联.每次请求都是相互独立的. 1.cookie简介 什么是会话跟踪技术我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会 ...

  3. [OpenCV-Python] OpenCV 中图像特征提取与描述 部分 V (一)

    部分 V图像特征提取与描述 OpenCV-Python 中文教程(搬运)目录 29 理解图像特征 目标本节我会试着帮你理解什么是图像特征,为什么图像特征很重要,为什么角点很重要等.29.1 解释 我相 ...

  4. 枚举 enumerate 让列表有序号

    把列表转字典,或序列对:

  5. hdu 2647 Reward(拓扑排序+反图)

    题目链接:https://vjudge.net/contest/218427#problem/C 题目大意: 老板要给很多员工发奖金, 但是部分员工有个虚伪心态, 认为自己的奖金必须比某些人高才心理平 ...

  6. 条件随机场之CRF++源码详解-训练

    上篇的CRF++源码阅读中, 我们看到CRF++如何处理样本以及如何构造特征.本篇文章将继续探讨CRF++的源码,并且本篇文章将是整个系列的重点,会介绍条件随机场中如何构造无向图.前向后向算法.如何计 ...

  7. 一次webapck4 配置文件无效的解决历程

    前言 升级webpack4,一定要去看文档,特别是更新说明,不要自持用过原本webpack就自己开始折腾.折腾到后面,可能就默默流下眼泪了. webpack4的变化 webpack-cli抽离 web ...

  8. WinForm中DataGridView导出为Excel(快速版)

    public static void ExportExcel(DataGridView myDGV, string fileName) { string saveFileName = fileName ...

  9. BZOJ.2287.[POJ Challenge]消失之物(退背包)

    BZOJ 洛谷 退背包.和原DP的递推一样,再减去一次递推就行了. f[i][j] = f[i-1][j-w[i]] + f[i-1][j] f[i-1][j] = f[i][j] - f[i-1][ ...

  10. php 解析HTTP协议六种请求方法,get,head,put,delete,post有什么区别

    GET: 请求指定的页面信息,并返回实体主体.HEAD: 只请求页面的首部.POST: 请求服务器接受所指定的文档作为对所标识的URI的新的从属实体.PUT: 从客户端向服务器传送的数据取代指定的文档 ...